Selected topic
Data Structures
Prefer practical output? Use related tools below while reading.
In JavaScript, an array is a fundamental data structure that stores a collection of values. Think of it as a list or a container that can hold multiple elements.
javascript
let colors = ['red', 'green', 'blue'];colors with three elements: 'red', 'green', and 'blue'.javascript
console.log(colors[0]); // Output: "red"javascript
console.log(colors[colors.length - 1]); // Output: "blue"javascript
colors[0] = 'yellow';
console.log(colors); // Output: ["yellow", "green", "blue"]colors array from 'red' to 'yellow'.push() method:javascript
colors.push('purple');
console.log(colors); // Output: ["yellow", "green", "blue", "purple"]splice() method. For example:javascript
colors.splice(2, 1);
console.log(colors); // Output: ["yellow", "green", "purple"]'blue') of the colors array.