Arrays & Array Methods
Difficulty: medium
Overview
Arrays are ordered, zero-indexed, and dynamically sized. Mutating methods: push, pop, shift, unshift, splice, sort, reverse, fill. Non-mutating methods: concat, slice, join, flat, includes, indexOf, find, findIndex. Spread (...) copies or merges arrays. Destructuring extracts elements into variables. Arrays are objects — assignment copies the reference, not the values.
Practice Linked Questions
Q1. What is the output? ```js const arr = [1, 2, 3]; arr.push(4); console.log(arr.length); ```
Select one answer before revealing.
Q2. Which array method removes elements from an array and can insert new ones in their place?
Select one answer before revealing.
Q3. What is the output? ```js const a = [1, 2, 3]; const b = [...a, 4, 5]; console.log(b); ```
Select one answer before revealing.
Q4. What is the output? ```js const [first, , third] = [10, 20, 30]; console.log(first, third); ```
Select one answer before revealing.
Q5. Which of the following array methods do NOT mutate the original array? (More than one answer may be correct.)
Select one answer before revealing.
Q6. What is the output? ```js const nums = [3, 1, 2]; nums.sort(); console.log(nums); ```
Select one answer before revealing.
Q7. What does `[1, 2, 3].includes(2)` return?
Select one answer before revealing.