Search⌘ K
AI Features

Manipulating Arrays in JavaScript

Explore fundamental techniques for manipulating arrays in JavaScript, including how to create arrays, access their elements using indexes, determine their size with the length property, and store various data types. This lesson helps you build a solid understanding of array operations essential for efficient data management in web development.

In JavaScript, an array is an object that has special properties.

Creating an array

Here’s how to create our list of movies in the form of an array.

Javascript (babel-node)
const movies = ["The Wolf of Wall Street", "Zootopia", "Babysitting"];

An array is created with a pair of square brackets []. Everything within the brackets makes up the array. You can store different types of elements within an array, including strings, numbers, booleans and even objects.

Javascript (babel-node)
const elements = ["Hello", 7, { message: "Hi mom" }, true];

Since an array may contain multiple elements, it’s good to name the array plurally (for example, movies).

Obtaining an array’s size

The number of elements stored in an ...