Array

An an array is a list of ordered, stored data. They can hold items that are of any data type.

Syntax

Arrays are often created by using square brackets, with individual elements separated by commas.

array = [element1, element2, element3, element4]

Index Number

We access an array element by referring to the index number. An index is the element’s position in a sequence.

A lot of times, array indices start with 0:

grocery = ["milk", "cookies", "berries", "carrots"]
// index: 0 1 2 3
  • The first element is at index 0.
  • The second element is at index 1.
  • The third element is at index 2.
  • …and so on.

Arrays in Different Languages

Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn More on Codecademy

Edit this page on GitHub

Contributors