JavaScript Array Methods Flashcards
length
gives the length of an array
pop( )
removes the last element
push(el)
add an element to the end
shift( )
Remove an element from the beginning
unshift(el)
adds an element to the beginning
join(“”)
Creates a string out of an array
toString()
Creates a string out of an array
.concat([])
Creates one array out of two
slice(begin, end, step)
Returns the sliced part but does NOT mutate the original array.
splice(start, amount, element, …)
mutates the original array by adding or removing elements.
sort((a, b) => a - b)
sorts an array in ascending or descending order.
delete arr[idx]
removes an element from an array.
.indexOf(element, start )
finds the index of the first element matching the one given to the method. start is optional and determines where should the search begin. Returns -1 if it doesn’t find the element.
.find(element )
returns the first element that satisfies the provided testing function otherwise returns undefined.
includes( )
determines whether an array includes a certain value among its entries, returning true or false as appropriate.
.at( integer )
takes an integer and return the item at that index, allowing for positive and negative integers.
.entries( )
returns an array that contains key/value pairs for each index in the array
.every(function, hisArg:optional)
checks if all the elements in the array pass the test. Returns a Boolean. if all pass the test returns true.
.some(function, hisArg:optional)
Checks if one element in the array passes the test. If one passes then returns true. Otherwise, returns false.
.filter(function, thisArg:optional)
creates a shallow copy of the elements in the array that pass the test.
findIndex(function, thisArg: Optional)
Returns the first index of element in an array that satisfies the testing function, returns -1 if nothing passes the test.
flat(depth:optional)
Creates a new array with all subarrays concatenated.
flatMap(function, thisArg:optional)
Returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level.
forEach(function, thisArg: optional)
Runs a function for each element in the array.
Array.from()
creates a new, shallow copy instance from an iterable or array-like object.
.keys()
returns an array iterator object that contains the keys for each index.
map(function, thisArg: optional)
creates a new array populated with the results of calling a provided function on every element in the calling array.
.reduce((acc, curr, idx)
instances executes a user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
reverse()
reverses the whole array