Categories
ECMAScript Javascript

Arrays

/**
 * to demonstrate working with Arrays in JS
 */

var colors; // declare
colors=["red","green","orange","black","Purple"]; //initialize with content as Array of Strings
console.log("colors.length::"+colors.length);
console.log("color at index 0 : "+colors[0]);


var squares = new Array(5);//to allocate sized array using array constructor
for(var i=0;i<5;i++)
	squares[i]=(i)*(i);
console.log("Array of squares ::"+squares);
console.log("size of squares arrah ::"+squares.length);


Output

Leave a comment

Design a site like this with WordPress.com
Get started