Javascript functions
Fri Jan 25 2019
Array
Array : Pure
concat([value1[, value2[, ...[, valueN]]]])
: merges many arrays together : a1.concat([1, 2], a3, a4)
, returns the merged array.
Array.from()
: creates a new, shallow copied Array instance from an array like or iterable object Array.from("hey", x => x.toUpperCase()); //["H", "E", "Y"]
filter(callback(element[, index[, array]])[, thisArg])
: creates a new array with all the elements that pass the test in callback
.
map(callback( currentValue[, index[, array]]))
: returns new array populated with the results of calling callback
on every element of the calling array.
reduce(callback( accumulator, currentValue[, index[, array]] )[, initialValue])
: executes callback
on each element of the array, resulting in a single output value.
reduceRight(callback(accumulator, currentValue[, index[, array]])[, initialValue])
: same as reduce
but starts reducing from the end
slice([begin[, end]])
: returns a shallow copy of a portion of an array into a new array object, selected from begin
to end
both being indexes.
join([spearator])
: joins and creates a new string from the elements of calling array-like.
flat([depth])
: creates a new array with all sub-array elements extracted and put in the first level array
flatMap(callback(currentValue[, index[, array]])[, thisArg])
map
but calls flat on the resulting array.
includes(valueToFind[, fromIndex])
returns true
if valueToFind
is found in array, false otherwise. Can find an object reference.
lastIndexOf(searchElement[, fromIndex])
same as includes
except it returns the index if found or -1
otherwise.
indexOf(searchElement[, fromIndex])
same as lastIndexOf
except it starts searching from the end.
keys()
: returns a new array with the keys
values()
: returns a new array iterator containing the values for each index in the array
some(callback[, thisArg])
: returns true if there exists some element in the calling array for which callback
returned true.
- Object.assign
toString()
: returns string version of the array.
Array : Impure
push(element1[, ...[, elementN])
: add element to end of array. ret = a.push(el)
: ret
is count of elements in a
after push
. a
contains. Similar pure version concat
pop()
: removes the last element from the calling array and returns that element.
forEach(callback(currentValue [, index [, array]])[, thisArg])
: perform callback on each element of array. Returns undefined
. No way to stop or break a forEach()
use for...of
/ for...in
or every()
, some()
, find()
or findIndex()
.
- pop() removes the last element from the calling array, and returns that element.
shift()
: removes the first element from the calling array and returns that element.
unshift(element1[, ...[, elementN]]])
: add elements to the front of array. Returns modified array length.
reverse()
: reverses the calling array in place.
sort([compareFunction(firstEl, secondEl)])
: sorts the elements of the calling array, ascending by default, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values. The compareFunction
should return -1
if firstEl
has less priority than seondEl
, 1
for the contrary, and 0
in case of equal priority.
splice(start[, deleteCount[, item1[, item2[, ...]]]])
: optionally insert item1, item2...
into the calling array, by optionally removing deleteCount
elements starting at index start
. If only start
is provided, returns the first start
elements.
Function
Properties
Methods
apply(thisArg[, argsArray])
calls a function with a given this
value and arguments provided as an array, like in apply
bind(thisArg[, arg1[, arg2[, ...argN]]])
method creates a new function that when called has its this
keyword set to thisArg
, and is passed the arg1
, ... prepended to the actual call arguments
call(thisArg[, arg1[, arg2[, ...argN]]])
same as apply
but arguments are provided as arguments to call
toString()