arrays

Array Methods in JavaScript

Array Methods in JavaScript

JavaScript provides several methods to manipulate arrays, making it easier to work with lists of data.

Common Array Methods

Example of Array Methods

      
        let fruits = ["apple", "banana", "cherry"];
        fruits.push("orange");  // Adds "orange"
        fruits.pop();            // Removes last element
        console.log(fruits);
      
    

Activity

Try It Yourself!

Create an array of numbers. Use push, pop, shift, and unshift to manipulate the array.

Quiz

Quick Quiz

  1. What does push() do?
  2. How do you remove the first element of an array?
  3. What does unshift() do?

Answers: Adds to end; shift(); adds to beginning.