Learn how to use arrays in JavaScript
Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026
The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.
An array is a collection of elements.
We can initialize an empty array in these 2 different ways:
const a = []
The first is using the array literal syntax.
You can pre-fill the array using this syntax:
const a = [1, 2, 3]
An array can hold any value, even value of different types, like numbers and strings or even other arrays:
const a = [1, 'Flavio', ['a', 'b']]
You can access any element of the array by referencing its index. The first item has index zero:
const a = [1, 2, 3]
a[0] //1
a[1] //2
a[2] //3