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"];
Accessing Array Elements:
You access an array element by referring to the index number
const cars = ["Saab", "Volvo", "BMW"];
let car = cars[0];
The output will be Saab
Top comments (0)