📘Array
🚧 under construction
JS ⟩ value ⟩ object⟩ built-in ⟩ Array
(Object)
an ordered collection of values.
each element has a numeric position in the array, known as its index.
JavaScript arrays are untyped:
an array element may be of any type.
different elements of the same array may be of different types.
array
inherits methods from Array.prototype, most of these methods are generic, they work correctly for any "array-like" object.
⚖️ array object properties vs. array elements
setting / accessing via anything other than nonnegative integers:
will not set / retrieve an array element
If an array literal contains multiple commas in a row, with no value between, the array is sparse.
other topics
🍄 array-like - object that has indexes and length.
🔰 accessing elements
pop() - remove and return last element.
unshift() - prepend element.
shift() - remove and return first element.
combine elements
reduce((result, element, index, array) => {...}) -
reduceRight - reduce array from highest index to lowest. (from right to left)
find & search elements
findIndex - returns index of first matching element, -1
otherwise.
every - returns true if every element satisfies the condition.
How to get first N number of elements from an array