-
An array is a data structure that stores a collection of elements, each identified by an index or a key.
-
Arrays provide a way to organize and access elements in a sequential manner.
-
Array indices in JavaScript start at 0. The first element is accessed using index 0, the second with index 1, and so on.
const arr = ['a', 'b', 'c', 'd'];
console.log(arr[1]); // b
- Unlike some languages where arrays have a fixed size, JavaScript arrays are dynamic and can grow or shrink dynamically. You can add or remove elements at any time.
- JavaScript arrays can store elements of different data types in the same array.
const mixedArray = [1, 'hello', true];
- JavaScript supports multi-dimensional arrays as well. You can create arrays of arrays to represent matrices or tables.
let matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
- In JavaScript, arrays come with many built-in properties and methods we can use with different purposes, such as adding or deleting items from the array, sorting it, filtering its values, know its, length and so on.
- MDN