Dense Arrays in JavaScript

 
A dense array is an array that has been created with each of its elements being assigned a specific value.
Dense arrays are used exactly in the same manner as other arrays. They are declared and initialized at the same time.

dense array can be created as :

ArrayName = new Array(value0,Value1,value2,……valueN)

In this array, since the element count starts from 0 to n, the array length is n +1.

dense array compresses the declaration and initialization of an array into one step. As we can see, we directly passed in the values of the array as parameters.

following are the example that show dense array declaration:

 var ArrDay=new Array("Sunday","Monday","Tuesday", "Wednesday","Thursday","Friday","Saturday")

one more important thing about array in JavaScript that JavaScript allows different types values or object in one array like this:

var DiffArray=new Array(35, "Author", 5 , 7, "Code", null, true, false, new array(2,3))

We can see above array has 9 elements or we can say above array has length 9 you can consider its elements as:
DiffArray[0] = 35
DiffArray[1] = “Author”
DiffArray[2] = 5
DiffArray[3] = 7
DiffArray[4] = “Code”
DiffArray[5] = null
DiffArray[6] = true
DiffArray[7] = false
DiffArray[8] = a new dense array that consist two elements 2 and 3

we can access last array elements as

var1 = DiffArray[8][0];
var2 = DiffArray[8][1];

One thought on “Dense Arrays in JavaScript”

Comments are closed.