Using Arrays in JavaScript – Basics

By | February 28, 2011


We all know, Arrays are nothing but variables which can hold all your variable values with a single name.

Let’s see some basic operations of Arrays in JavaScript.

To Create a New Array. Use the following code.

 var myArray = new Array();

This code of line created a new Array object called myArray.

Adding Elements to myArray

myArray[0]= "you";
myArray[1] = "me";
myArray[2] = "we";


var myArray=new Array("you","me","we"); 


var myArray=["you","me","we"];

Accessing Array Elements


It will print ‘you’!


Leave a Reply

Your email address will not be published. Required fields are marked *