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 (,).