Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, November 5, 2012

Codecademy: Sample Solution to "Awesome Arrays Are Always Allocated"



//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


This is an example of scrolling text using Javascript.

Popular Posts