🚧 under construction
JS ⟩ value ⟩ object⟩ built-in ⟩ Array
(Object)
an ordered collection of values.
each value is called an element.
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.
arrays are iterated "live"❗️
array
is iterable
is not associated 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
thery are separate❗
array's traversal and mutation operations cannot be applied to these named properties.
setting / accessing via anything other than nonnegative integers:
will not set / retrieve an array element
will set / access one of the array's object properties.
deleting an array element leaves a “hole” in the array and does not change the array’s length❗ (sparse array)
If an array literal contains multiple commas in a row, with no value between, the array is sparse.
🔸element
🔸element index
🔸array object property
🔰 creating arrays
🔢array literal
🔰 accessing elements
🔰 iterating elements
🔰 extending Array
Array extension
other topics
🍄 array-like - object that has indexes and length.
🍄 sparse array - array that has "holes" in it.
push() - append element.
pop() - remove and return last element.
unshift() - prepend element.
shift() - remove and return first element.
combine elements
join - 連接所有元素、合併成一個字串。
reduce((result, element, index, array) => {...}) -
reduceRight - reduce array from highest index to lowest. (from right to left)
find & search elements
find - 回傳第一個符合條件的元素。否則回傳 undefined。
undefined
findIndex - returns index of first matching element, -1 otherwise.
-1
includes - 判斷陣列是否包含特定元素。
some - 測試陣列中是否有符合條件的元素。
every - returns true if every element satisfies the condition.
NodeList vs. Array
Array is iterable.
bracket notation [] is used to access element.
JavaScript: The Definitive Guide > Ch. 7 Arrays
Guides ⟩ Arrays ⭐️
Array ⟩
array elements cannot be accessed using arbitrary strings as indexes
codepen ⟩ Array: intersection, union, difference ...
randomPassword()
randomInt()
( 🚧 to be removed ... )
matrix methods (instance):
mat.transpose() - see matrix in "columns"
mat.matrixMap()
mat.maxElementInEachColumn() - for number matrices only.
How to get first N number of elements from an array
Remove empty elements from an array
Last updated 1 year ago