Exploring arrays
Arrays are non-primitive values; they are a collection of values. The values can be any type of value, including other arrays. Arrays are mutable, which means that you can modify them and the changes will be reflected in the original array.
Arrays are zero-indexed, which means that the first element is at index 0, the second element is at index 1, and so on.
The Array.isArray()
method determines whether the passed value is an array:
const array = [1, 2, 3]; console.log(Array.isArray(array)); // true const object = { name: "Ulises" }; console.log(Array.isArray(object)); // false console.log(typeof array); // object console.log(typeof object); // object console.log("are object and array the same type?", typeof(array) === typeof(object)); // true
As arrays are objects, you need to be careful because they can’t be compared with the ===
or ==
operator, because it will compare the references, not the values:
const array1 = [1, 2,...