Search⌘ K

Updating an Array's Content

Explore how to update array contents in JavaScript by adding elements with push and unshift methods and removing them with pop and splice. Understand each method's use to manage data effectively within arrays.

Adding an element to an array

Now, let’s add another movie to our list: Ghostbusters.

Javascript (babel-node)
const movies = ["The Wolf of Wall Street", "Zootopia", "Babysitting"];
movies.push("Ghostbusters");
console.log(movies[3]); // "Ghostbusters"

You add a new item to an array with the ...