๐array methods
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS โฉ object โฉ built-in โฉ Array โฉ methods
๐ฐ accessing elements
push() - append element.
pop() - remove and return last element.
unshift() - prepend element.
shift() - remove and return first element.
- delete/insert elements.
filter elements
- "holes" are removed automatically.
combine elements
- ้ฃๆฅๆๆๅ ็ด ใๅไฝตๆไธๅๅญไธฒใ
reduce((result, element, index, array) => {...}) -
find & search elements
- ๅๅณ็ฌฌไธๅ็ฌฆๅๆขไปถ็ๅ ็ด ใๅฆๅๅๅณ ใ
- returns index of first matching element,
sort elements
- reverse an array in place.
transform arrays/elements
map -
- flatten nested arrays to the specified level (1
if not specified
-1
includes - ๅคๆท้ฃๅๆฏๅฆๅ ๅซ็นๅฎๅ ็ด ใ
some - ๆธฌ่ฉฆ้ฃๅไธญๆฏๅฆๆ็ฌฆๅๆขไปถ็ๅ ็ด ใ
every - returns true if every element satisfies the condition.
flatMap - similar to arr.map(f).flat()
.