Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Modifying Arrays and Accessing Elements | Mastering JavaScript Arrays
JavaScript Data Structures

bookModifying Arrays and Accessing Elements

12345
const weekdays = ["Monday", "Tuesday", "Wednesday"]; weekdays[0] = "Lunes"; weekdays[1] = "Martes"; console.log(weekdays); // Output: Lunes, Martes, Wednesday
copy
123
const mountains = ["Everest", "K2", "Kangchenjunga", "Lhotse"]; console.log(mountains.length); // Output: 4
copy
1234
const vehicles = ["car", "bike", "bus", "train"]; const lastIndex = vehicles.length - 1; console.log(vehicles[lastIndex]); // Output: train
copy
question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain more about how array indexing works in JavaScript?

What happens if I try to access an index that doesn't exist in the array?

Can you show how to add or remove elements from an array?

bookModifying Arrays and Accessing Elements

Swipe to show menu

12345
const weekdays = ["Monday", "Tuesday", "Wednesday"]; weekdays[0] = "Lunes"; weekdays[1] = "Martes"; console.log(weekdays); // Output: Lunes, Martes, Wednesday
copy
123
const mountains = ["Everest", "K2", "Kangchenjunga", "Lhotse"]; console.log(mountains.length); // Output: 4
copy
1234
const vehicles = ["car", "bike", "bus", "train"]; const lastIndex = vehicles.length - 1; console.log(vehicles[lastIndex]); // Output: train
copy
question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

question mark

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 3
some-alt