Array Flashcards
Array.from()
create an array from an array-like
params: arrayLike[, mapFn[, thisArg]]
arrayLike
An array-like or iterable object to convert to an array.
mapFn
Optional. Map function to call on every element of the array.
thisArg
Optional. Value to use as this when executing mapFn.
Array.isArray()
Determine if the passed in object is an array
params: obj
Note: necessary because an array from a different window might have an augmented Array.prototype, in which case instanceof might not work across the different windows.
Array.observe()
Asynchronously observe changes
params: arr, callback
arr
The array to observe
callback
The callback. Takes an array of change objects. Change objects have [propertyName, changedArray, typeOfChange, oldValue (for update and delete types), index + removed + addedCount (for splice type)]
Array.of()
Creates a new array from a list of args
params: element0[, …elementN]
Array.prototype.concat()
Returns combined arrays
params: arr1[, …arrN]
Array.prototype.copyWithin()
(Mutable) Copies part of an array to another part
params: target, start[, end]
target the index to start inserting start the start of the copy range end the end of the copy range, exclusive
Array.prototype.entries()
Returns a new Array Iterator. Each iteration returns an array [k, v]
Array.prototype.every()
Tests whether all elements pass a test
params: callback[, thisArg]
callback
args are [currentValue, index, arr]. return T/F
thisArg
the this binding for the callback
Array.prototype.fill()
fill an array with a value
params: value[, start[, end]]
value value to use start start index end end index, exclusive
Array.prototype.filter()
Return a new array with only elements that pass the test
params: callback[, thisArg]
callback
args [elem, index, arr]. returns T/F
thisArg
the this binding for the callback
Array.prototype.find()
Returns a value from the array if an element satisfies the test
params: callback[, thisArg]
callback
Test (element, index, array)
thisArg
this binding
Array.prototype.findIndex()
Returns the first index of an element that satisfies the test
params: callback[, thisArg]
callback
Test (element, index, array)
thisArg
this binding
Array.prototype.forEach()
Executes a callback on each element of an array
params: callback[, thisArg]
callback
function (currentValue, index, arr)
thisArg
this binding
Array.prototype.includes()
Returns true if the array includes a value
params: searchElement[, fromIndex]
Array.prototype.indexOf()
Returns first index of an element
params: searchElement[, fromIndex=0]
Array.prototype.join()
joins all elements into a string
params: [separator = ‘,’]
Note: separator is converted to string
Array.prototype.keys()
Returns an array iterator with keys for each index
Note: does not ignore holes like Object.keys() does
Array.prototype.lastIndexOf()
Returns last index of fiven element
params: searchElement[, fromIndex = arr.length-1]
Array.prototype.map()
Creates a new array with results of calling function on each element in array
params: callback[, thisArg]
callback
(currentValue, index, array)
Array.prototype.pop()
Removes & returns last element
Note: intentionally generic, so you can call/apply it on objects resembling arrays
Array.prototype.push()
Adds one or more elements. Returns new length
params: element1, …, elementN
Note: intentionally generic, so you can call/apply on objects resembling arrays
Array.prototype.reduce()
Reduces an array to a single value
params: callback[, initialValue]
callback
(prevVal, currentVal, index, arr)
initialValue
first prevVal
Array.prototype.reduceRight()
reduce from the right
Array.prototype.reverse()
Reverse an array in place
Array.prototype.shift()
Remove and return first element
Note: intentionally generic
Array.prototype.slice()
Returns a shallow copy of part of the array
params: begin[, end]
begin
if negative, offset is from end. (-2) returns last two
end
exclusive. if negative, offset is from end
Array.prototype.some()
Test whether at least one element passes a test
params: callback[, thisArg]
callback
(value, i, arr)
thisArg
this binding
Array.prototype.sort()
Sorts an array in place
params: [compareFunction]
compareFunction
(a,b)
Note: numbers are converted to strings
Array.prototype.splice()
Changes an array by adding/removing elements. Returns removed elements
params: start[, deleteCount[, item1[, itemN]]]
start if negative, will begin that many elements from end deleteCount number of elements to delete itemN elements to add
Array.prototype.toLocaleString()
Returns a string representing elements in the array in locale-specific format
Array.prototype.toString
outputs comma separated elements
Array.prototype.unshift()
Adds elements to the beginning of a string
params: item1[, itemN]
Note: intentionally generic
Array.prototype.values()
Returns an iterator with the values
Array.unobserve
Remove observers set by observe
params: arr, callback
arr
the array to stop observing
callback
The reference to the observer that should not be called anymore