The JavaScript Array class is a global object that is used in the construction of arrays; which are high-level, list-like objects.
Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed. Since an array’s length can change at any time, and data can be stored at non-contiguous locations in the array, JavaScript arrays are not guaranteed to be dense; this depends on how the programmer chooses to use them. In general, these are convenient characteristics; but if these features are not desirable for your particular use, you might consider using typed arrays.
There are 3 ways to construct an array in JavaScript
- JavaScript array literal - The syntax of creating an array using array literal is given below:
var arrayname=[value1,value2.....valueN];
- JavaScript Array directly (new keyword) - The syntax of creating an array directly is given below:
var arrayname=new Array();
- JavaScript array constructor (new keyword) - Here, you need to create instance of array by passing arguments in constructor so that we don’t have to provide value explicitly.