Javascript functions
2019-01-25T22:20:32.169Z
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 objectArray.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 incallback
.map(callback( currentValue[, index[, array]]))
: returns new array populated with the results of callingcallback
on every element of the calling array.reduce(callback( accumulator, currentValue[, index[, array]] )[, initialValue])
: executescallback
on each element of the array, resulting in a single output value.reduceRight(callback(accumulator, currentValue[, index[, array]])[, initialValue])
: same asreduce
but starts reducing from the endslice([begin[, end]])
: returns a shallow copy of a portion of an array into a new array object, selected frombegin
toend
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 arrayflatMap(callback(currentValue[, index[, array]])[, thisArg])
map
but calls flat on the resulting array.includes(valueToFind[, fromIndex])
returnstrue
ifvalueToFind
is found in array, false otherwise. Can find an object reference.lastIndexOf(searchElement[, fromIndex])
same asincludes
except it returns the index if found or-1
otherwise.indexOf(searchElement[, fromIndex])
same aslastIndexOf
except it starts searching from the end.keys()
: returns a new array with the keysvalues()
: returns a new array iterator containing the values for each index in the arraysome(callback[, thisArg])
: returns true if there exists some element in the calling array for whichcallback
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 ina
afterpush
.a
contains. Similar pure versionconcat
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. Returnsundefined
. No way to stop or break aforEach()
usefor...of
/for...in
orevery()
,some()
,find()
orfindIndex()
.- 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. ThecompareFunction
should return-1
iffirstEl
has less priority thanseondEl
,1
for the contrary, and0
in case of equal priority.splice(start[, deleteCount[, item1[, item2[, ...]]]])
: optionally insertitem1, item2...
into the calling array, by optionally removingdeleteCount
elements starting at indexstart
. If onlystart
is provided, returns the firststart
elements.
Function
Properties
arguments
length
name
Methods
apply(thisArg[, argsArray])
calls a function with a giventhis
value and arguments provided as an array, like in applybind(thisArg[, arg1[, arg2[, ...argN]]])
method creates a new function that when called has itsthis
keyword set tothisArg
, and is passed thearg1
, … prepended to the actual call argumentscall(thisArg[, arg1[, arg2[, ...argN]]])
same asapply
but arguments are provided as arguments tocall
toString()