Creating and Accessing Arrays


Before working with arrays, you need to know how to create them and how to access the values stored inside.

In JavaScript, arrays are created using square brackets []. Each value inside the array is called an element, and every element has a position number called an index.

Learning how to create arrays and access their elements is the first practical step in working with collections of data.

Ways to Create Arrays in JavaScript

  • Using square brackets []
  • Using the new Array() constructor  

The square bracket method is the most common and recommended way.

This example creates an array called colors with three values.

Each value is stored in a specific position inside the array.

Arrays in JavaScript start counting from index 0.

This means:

  • colors[0] gives the first value  
  • colors[1] gives the second value  
  • colors[2] gives the third value  

This example shows how to change a value inside an array by using its index.

By mastering array creation and access, students gain the foundation needed to work with advanced array operations in real-world applications.