Array Methods Flashcards
Joins arrays and returns an array with the joined arrays
concat()
array1.concat(array2, array3, …, arrayX)
The concat() method concatenates (joins) two or more arrays.
The concat() method returns a new array, containing the joined arrays.
The concat() method does not change the existing arrays.
Returns the function that created the Array object’s prototype
constructor
array.constructor
The constructor property returns the function that created the Array prototype.
For JavaScript arrays the constructor property returns:
function Array() { [native code] }
Copies array elements within the array, to and from specified positions
copyWithin()
array.copyWithin(target, start, end)
The copyWithin() method copies array elements to another position in the array.
The copyWithin() method overwrites the existing values.
The copyWithin() method does not add items to the array.
Returns a key/value pair Array Iteration Object
entries()
array.entries()
The entries() method does not change the original array.
Checks if every element in an array pass a test
every()
array.every(function(currentValue, index, arr), thisValue)
The every() method executes a function for each array element.
The every() method returns true if the function returns true for all elements.
The every() method returns false if the function returns false for one element.
The every() method does not execute the function for empty elements.
The every() method does not change the original array
Fill the elements in an array with a static value
fill()
array.fill(value, start, end)
The fill() method fills specified elements in an array with a value.
The fill() method overwrites the original array.
Start and end position can be specified. If not, all elements will be filled.
Creates a new array with every element in an array that passes a test
filter()
array.filter(function(currentValue, index, arr), thisValue)
The filter() method creates a new array filled with elements that pass a test provided by a function.
The filter() method does not execute the function for empty elements.
The filter() method does not change the original array.
Returns the value of the first element in an array that passes a test
find()
array.find(function(currentValue, index, arr),thisValue)
The find() method returns the value of the first element that passes a test.
The find() method executes a function for each array element.
The find() method returns undefined if no elements are found.
The find() method does not execute the function for empty elements.
The find() method does not change the original array.
Returns the index of the first element in an array that pass a test
findIndex()
array.findIndex(function(currentValue, index, arr), thisValue)
The findIndex() method executes a function for each array element.
The findIndex() method returns the index (position) of the first element that passes a test.
The findIndex() method returns -1 if no match is found.
The findIndex() method does not execute the function for empty array elements.
The findIndex() method does not change the original array.
Calls a function for each array element
forEach()
array.forEach(function(currentValue, index, arr), thisValue)
The forEach() method calls a function for each element in an array.
The forEach() method is not executed for empty elements.
Creates an array from an object
from()
Array.from(object, mapFunction, thisValue)
The Array.from() method returns an array from any object with a length property.
The Array.from() method returns an array from any iterable object.
Check if an array contains the specified element
includes()
array.includes(element, start)
The includes() method returns true if an array contains a specified value.
The includes() method returns false if the value is not found.
The includes() method is case sensitive.
Searches the array for an element and returns its position
indexOf()
array.indexOf(item, start)
The indexOf() method returns the first index (position) of a specified value.
The indexOf() method returns -1 if the value is not found.
The indexOf() method starts at a specified index and searches from left to right.
By default the search starts at the first element and ends at the last.
Negative start values counts from the last element (but still searches from left to right).
Checks whether an object is an array
isArray()
Array.isArray(obj)
The isArray() method returns true if an object is an array, otherwise false.
Joins all elements of an array into a string
join()
array.join(separator)
The join() method returns an array as a string.
The join() method does not change the original array.
Any separator can be specified. The default is comma (,).
Returns a Array Iteration Object, containing the keys of the original array
keys()
array.keys()
The keys() method returns an Array Iterator object with the keys of an array.
The keys() method does not change the original array.
Search the array for an element, starting at the end, and returns its position
lastIndexOf()
array.lastIndexOf(item, start)
The lastIndexOf() method returns the last index (position) of a specified value.
The lastIndexOf() method returns -1 if the value is not found.
The lastIndexOf() starts at a specified index and searches from right to left.
By defalt the search starts at the last element and ends at the first.
Negative start values counts from the last element (but still searches from right to left).
Sets or returns the number of elements in an array
length
array. length
array. length = number
The length property sets or returns the number of elements in an array.
Creates a new array with the result of calling a function for each array element
map()
array.map(function(currentValue, index, arr), thisValue)
map() creates a new array from calling a function for every array element.
map() calls a function once for each element in an array.
map() does not execute the function for empty elements.
map() does not change the original array.
Removes the last element of an array, and returns that element
pop()
array.pop()
The pop() method removes (pops) the last element of an array.
The pop() method changes the original array.
The pop() method returns the removed element.
Allows you to add properties and methods to an Array object
prototype
Array.prototype.name = value
prototype allows you to add new properties and methods to arrays.
prototype is a property available with all JavaScript objects.
Adds new elements to the end of an array, and returns the new length
push()
array.push(item1, item2, …, itemX)
The push() method adds new items to the end of an array.
The push() method changes the length of the array.
The push() method returns the new length.
Reduce the values of an array to a single value (going left-to-right)
reduce()
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
The reduce() method executes a reducer function for array element.
The reduce() method returns a single value: the function’s accumulated result.
The reduce() method does not execute the function for empty array elements.
The reduce() method does not change the original array.
Reduce the values of an array to a single value (going right-to-left)
reduceRight()
array.reduceRight(function(total, currentValue, currentIndex, arr), initialValue)
The reduceRight() method executes a reducer function for each array element.
The reduceRight() method works from right to left.
The reduceRight() method returns a single value: the function’s accumulated result.
The reduceRight() method does not execute the function for empty elements.