//create an array
var myArray = [1,2,3];
//find the length of it using .length
var arrayLength = myArray.length;
//get the first element of the array (using brackets!)
var firstElement = myArray[0];
//iterate through it, calling console.log
//for every element
for(var i=0; i<arrayLength; i++)
{
console.log("Element " + i + " is " + myArray[i]);
//since console.log won't be visible
alert(myArray[i]);
}
No comments:
Post a Comment