- Back to Home »
- Ex:7 Arrays
Posted by : Sushanth
Thursday, 17 December 2015
Arrays:
- Multiple values can be stored in a single variable using arrays
- Arrays can be created any of the below ways
1. var companies =new Array();
companies [0]="google";
companies [1]="microsoft";
companies [2]="samsung";
- Multiple values can be stored in a single variable using arrays
- Arrays can be created any of the below ways
1. var companies =new Array();
companies [0]="google";
companies [1]="microsoft";
companies [2]="samsung";
2. var companies =new Array("google","microsoft","samsung");
3. var companies =["google","microsoft","samsung"];
length is a predefined method of an array.Similarly index of is a method of array.
Objects of different types can be stored in one array.IN Javascript,all variables are objects.
Similarly all array objects are variables.All functions are also considered as objects
Because of this, you can have variables of different types in the same Array.
Similarly all array objects are variables.All functions are also considered as objects
Because of this, you can have variables of different types in the same Array.
Example:
myArr[0]=Date.now;
myArr[1]=myFunc();
myArr[2]=companies;
myArr[0]=Date.now;
myArr[1]=myFunc();
myArr[2]=companies;