Iterate with JavaScript For Loops

// Example
var ourArray = ;

for (var i = 0; i < 5; i++) {
ourArray.push(i);
}

// Setup
var myArray = ;

// Only change code below this line.
for (var i = 1; i < 6; i++) {
myArray.push(i);
}

I have finish this challenge, and i m just wondering the role of “myArray.push(i)” .

It appends an element to the end of the array. Here’s an example from the documentation for it on MDN:

var animals = ['pigs', 'goats', 'sheep'];

console.log(animals.push('cows'));
// expected output: 4

console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]
1 Like

Yes Yes i recall it now… Thanks