Array is an object that can store many values of the same type. This means that numerical array can store many numerical values and string array can store many string values. You can refer to an element of the array by using its index. The index of the array starts from 0. So the first element of the array is at index 0. To declare an array, you must write its name.
nArray = new Array(10);
sArray= new Array(5);
-The word nArray is the name of the array
-The new keyword is used to create array object
-The value 10 or 5 is the size of the array
-The element of array starts from index 0. This means that the nArray has 10 elements which starts from 0 to 9. The sArray has 5 elements which start from 0 to 4.
-Assign values to an array
You can assign values to an array by specifying its index in brackets , as shown below. You can not specify an index that is not in the range. If you try to violate the rule, you will get an error.
nArray = 1;
nArray = 2;
myArray = 3;
Note: you can declare an array without specifying it size. Therefore, its size can be flexible.
Note: you can use length property of the array to access the number of elements of the array:
var no= myArray.length;
You can also sort that array by calling sort() method:
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: