Const arr new array
A new array!
In JavaScript, you can create a new array using the following methods:
- Literal notation:
const arr = [];
- Array constructor:
const arr = new Array();
- Array.from():
const arr = Array.from();
- Spread operator:
const arr = [...];
Here's an example of each method:
Literal notation
const arr = [];
console.log(arr); // Output: []
Array constructor
const arr = new Array();
console.log(arr); // Output: []
Array.from()
const arr = Array.from();
console.log(arr); // Output: []
Spread operator
const arr = [...];
console.log(arr); // Output: []
Note that the spread operator is not a direct way to create an empty array, but you can use it to create a new array from an existing array or an iterable.
Which method do you prefer?