Saturday 1 September 2018

JavaScript: Define array using Array constructor function

In my previous post, I explained how to create an array using literal([]) notation. you can even define an array using Array constructor function.

var arr1 = new Array()
Above statement creates an empty array.

var arr2 =  new Array(10)
Above statement creates an array of size 10.

In addition to above, we can specify array by passing elements of array as arguments to constructor function.

var arr3 = new Array(1, 123.45, 5, 43);


Previous                                                 Next                                                 Home

No comments:

Post a Comment