Complete the code to create an array with three numbers.
const numbers = [1, 2, [1]];
The array should contain the number 3 as the third element, not a string or other value.
Complete the code to access the first element of the array.
const first = numbers[1];Arrays use square brackets with the index number to access elements. Indexing starts at 0.
Fix the error in the code to add a new element to the array.
numbers.[1](4);
The correct method to add an element at the end of an array in TypeScript is push.
Fill both blanks to create an array of squares for numbers 1 to 5.
const squares = [[1]]; for(let i = 1; i <= 5; i++) { squares.push(i [2] i); }
The array starts empty or with the squares listed. The loop multiplies i by i using '*'.
Fill all three blanks to create a filtered array of even numbers from 1 to 10.
const evens = []; for(let num = 1; num <= 10; num++) { if(num [1] 2 === 0) { evens.[2](num); } } console.log(evens); // [3]
The modulo operator '%' checks for even numbers. The 'push' method adds numbers to the array. The final array contains even numbers from 2 to 10.
