Complete the code to create an empty array.
const arr = [1];The correct way to create an empty array in JavaScript is using square brackets [].
Complete the code to create an array with three numbers: 1, 2, and 3.
const numbers = [1];Arrays with elements are created using square brackets with values separated by commas.
Fix the error in the code to create an array with the string 'hello'.
const greetings = [1];Arrays must be created with square brackets. Curly braces create objects, parentheses group expressions, and quotes alone create strings.
Fill both blanks to create an array of squares for numbers 1 to 5.
const squares = Array.from({length: 5}, (_, [1]) => ([2] + 1) * ([2] + 1));
The callback function receives the index as the second argument. Using index to represent it is clear and common. The square is calculated by multiplying (index + 1) by (index + 1).
Fill all three blanks to create an array of even numbers from 2 to 10.
const evens = Array.from({length: [1], (_, [2]) => ([3] + 1) * 2);
The array length is 5 for numbers 2,4,6,8,10. The index variable is commonly named index. The formula uses (index + 1) * 2 to get even numbers starting from 2.