The Array() constructor creates Array objects. You can declare an array with the "new" keyword to instantiate the array in memory. Here’s how you can declare new Array() constructor:
Let's see an example where the array has five elements:
The new keyword only complicates the code. It can also produce some unexpected results.
Instead of new Array() , you can use square brackets . Using square brackets is called the "array literal notation":
Line breaks and spaces are not important. The declaration can span multiple lines like in this example:
Using Array literal notation if you put a number in the square brackets it will return the number while using new Array() if you pass a number to the constructor, you will get an array of that length.
you call the Array() constructor with two or more arguments, the arguments will create the array elements. If you only invoke one argument, the argument initializes the length of the new array; the new array's elements are not initialized.