How to create an array in JavaScript?
Before going for the above question we should be clear about What is an Array?
An array is a sequential collection of variables or we can say an array is a special variable, which can hold more than one value at a time.
You can create an array using either
an array initializer (array literal)
example:
var Arr1 = [1,3,5,7,9]
or the Array constructor.
example:
var Arr1 = new Arr(1,3,5,7,9) // an array with 5 elements
How to access the Elements of an Array
To refer an array element can be done by referring to the index number.
This statement accesses the value of the first element in Arr1: var element = Arr1[0]
0 Comment(s)