๐ง 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 2 years ago
Was this helpful?