Complete the code to access the first element of the array.
const fruits = ['apple', 'banana', 'cherry']; console.log(fruits[[1]]);
Arrays in JavaScript start at index 0, so the first element is at index 0.
Complete the code to access the last element of the array.
const colors = ['red', 'green', 'blue', 'yellow']; console.log(colors[colors.length [1] 1]);
To get the last element, subtract 1 from the array's length because indexes start at 0.
Fix the error in the code to correctly access the second element.
const numbers = [10, 20, 30, 40]; console.log(numbers[[1]]);
The second element is at index 1 because counting starts at zero.
Fill both blanks to create an array of squares for numbers greater than 2.
const numbers = [1, 2, 3, 4, 5]; const squares = numbers.filter(n => n [1] 2).map(n => n [2] n); console.log(squares);
Filter numbers greater than 2, then multiply each number by itself to get squares.
Fill all three blanks to create an object mapping each fruit to its length if length is greater than 5.
const fruits = ['apple', 'banana', 'cherry', 'date']; const result = {}; for (let [1] of fruits) { if ([1].length > 5) { result[[1]] = [2]; } } console.log(result);
This uses a for...of loop to iterate over the array and build an object mapping fruit names to their lengths if the length is greater than 5. BLANK_1 is the loop variable name, BLANK_2 is the value (length), and BLANK_3 is the loop keyword for.