AlgoCademy
Lesson
Code

Accessing array elements in {lang}


Arrays are ordered, meaning each element has a numbered position known as its index. We access an array element by referring to its index number.

Arrays use zero-based indexing, so the first element in an array has an index of 0, the second element has an index of 1, etc.

We’re using bracket notation ([]) with the index after the name of the array to access the element:

let myArray = ["Hello world!", 32, false];

console.log(myArray[0]); // Output: "Hello world!"
console.log(myArray[1]); // Output: 32
console.log(myArray[2]); // Output: false

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.