Iterate with JavaScript For Loops

Iterate with JavaScript For Loops
0

#1

// 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)” .


#2

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"]

#3

Yes Yes i recall it now… Thanks