Manipulating Arrays
Learn to create, manipulate, and traverse arrays, including 2D arrays, in JavaScript.
We'll cover the following...
An array in JavaScript is a data structure used to store multiple values in a single variable. These values can be of any data type, and arrays are especially useful for managing lists or sequences of items. Arrays in JavaScript are zero-indexed, meaning the first element is accessed with an index 0
.
Syntax of arrays
The syntax of arrays in JavaScript is as follows:
let arrayName = [element1, element2, element3];
An example is given below.
let fruits = ["apple", "banana", "cherry"];
An array fruits
is defined with three elements: "apple"
, "banana"
, and "cherry"
. Each element can be accessed using its index, e.g., fruits[0]
returns "apple"
.
Press + to interact
let fruits = ["apple", "banana", "cherry"];console.log(fruits[0]);
Creating arrays with new Array
JavaScript also ...
Access this course and 1400+ top-rated courses and projects.