QWhat is the correct way to create a new array in JavaScript?
Question Info
Choose the Best Option
Click any option to instantly check if you're correct.
Explanation
In JavaScript, let arr = []; is the correct way to create a new array.
This is known as an array literal, and it is the most concise and commonly used way to create an array in JavaScript.
An array literal is a simple way to create an array by enclosing a list of values in square brackets ([]).
Each value in the list is called an element of the array, and the elements are separated by commas.
For example, the following code creates an array of numbers:
let arr = [1, 2, 3, 4, 5];
The following code creates an array of strings:
let arr = ['a', 'b', 'c', 'd', 'e'];
And the following code creates an array of mixed data types:
let arr = [1, 'a', true, {}, []];
Share This Question
Challenge a friend or share with your study group.