Lesson 13 / 38

Array Basics & Indexing

Creating arrays and accessing elements by index.

Creating & indexing

Arrays are zero-indexed, and .length always reflects the current size.

const fruits = ["apple", "banana", "cherry"];
console.log(fruits[0]);        // apple
console.log(fruits.length);    // 3
console.log(fruits[fruits.length - 1]); // cherry

Arrays are objects

Arrays are a special kind of object with numeric keys and a length property that updates automatically.

Out-of-range access

Accessing an index beyond the array's length returns undefined, not an error.