2018-10-08 13:34:43 -04:00

1.7 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
56bbb991ad1ed5201cd392cb Manipulate Arrays With push() Manipular matrices con empuje () 1

Description

Una forma fácil de agregar datos al final de una matriz es a través de la función push() . .push() toma uno o más parámetros y los "empuja" al final de la matriz.
var arr = [1,2,3];
arr.push(4);
// arr is now [1,2,3,4]

Instructions

Presione ["dog", 3] en el extremo de la variable myArray .

Tests

tests:
  - text: &#39; <code>myArray</code> ahora debe ser igual a <code>[[&quot;John&quot;, 23], [&quot;cat&quot;, 2], [&quot;dog&quot;, 3]]</code> .&#39;
    testString: 'assert((function(d){if(d[2] != undefined && d[0][0] == "John" && d[0][1] === 23 && d[2][0] == "dog" && d[2][1] === 3 && d[2].length == 2){return true;}else{return false;}})(myArray), "<code>myArray</code> should now equal <code>[["John", 23], ["cat", 2], ["dog", 3]]</code>.");'

Challenge Seed

// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.push(["happy", "joy"]);
// ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]]

// Setup
var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line.


After Test

console.info('after the test');

Solution

var myArray = [["John", 23], ["cat", 2]];
myArray.push(["dog",3]);