Accessing Elements

Reading and writing array elements.

Examples

Read Element

Accessing the first element.

const cars = ["Saab", "Volvo", "BMW"];
let x = cars[0];
console.log(x); // Saab

Change Element

Modifying an element.

const cars = ["Saab", "Volvo", "BMW"];
cars[0] = "Opel";
console.log(cars); // ["Opel", "Volvo", "BMW"]

Access Full Array

Converting array to string automatically when displaying.

const cars = ["Saab", "Volvo", "BMW"];
document.getElementById("demo").innerHTML = cars;

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.