1.8 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
56bbb991ad1ed5201cd392ce Manipulate Arrays With unshift() Manipular matrices con unshift () 1

Description

No solo puede shift elementos del principio de una matriz, unshift también puede unshift elementos al principio de una matriz, es decir, agregar elementos delante de la matriz. .unshift() funciona exactamente como .push() , pero en lugar de agregar el elemento al final de la matriz, unshift() agrega el elemento al principio de la matriz.

Instructions

Añadir ["Paul",35] para el inicio de la myArray variable usando unshift() .

Tests

tests:
  - text: ' <code>myArray</code> debería tener ahora [[&quot;Paul&quot;, 35], [&quot;dog&quot;, 3]].'
    testString: 'assert((function(d){if(typeof d[0] === "object" && d[0][0] == "Paul" && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == "dog" && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), "<code>myArray</code> should now have [["Paul", 35], ["dog", 3]].");'

Challenge Seed

// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy");
// ourArray now equals ["Happy", "J", "cat"]

// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();

// Only change code below this line.


After Test

console.info('after the test');

Solution

var myArray = [["John", 23], ["dog", 3]];
myArray.shift();
myArray.unshift(["Paul", 35]);