DEV Community

Mark Tony
Mark Tony

Posted on

JS - Arrays

Array

  • An Array is an object type designed for storing data collections. It contains list of values, known as elements.
  • Array elements are ordered based on their index.
  • The first element is at index 0, the second at index 1, and so on.
  • An Array can store any kind of data type (String, Number, Boolean, Objects, Null, Function)

Why Use Arrays?
An array can store multiple values under a single name,and you can access the values by referring to an index number.

Creating an array:

const cars = ["Saab", "Volvo", "BMW"];
Enter fullscreen mode Exit fullscreen mode

Accessing Array Elements:

You access an array element by referring to the index number

const cars = ["Saab", "Volvo", "BMW"];
let car = cars[0];
Enter fullscreen mode Exit fullscreen mode
The output will be Saab
Enter fullscreen mode Exit fullscreen mode

Top comments (0)