JS Arrays Flashcards
array1.concat(array2, array3, …, arrayX)
Returns Array. Joins two or more arrays, and returns a copy of the joined arrays
array.copyWithin(target, ?start, ?end)
target: The index position to copy the elements to
start: The index position to start copying elements from (default is 0)
end: The index position to stop copying elements from (default is array.length)
Returns modified Array. Copies array elements within the array, to and from specified positions
array.every(function(currentValue, ?index, ?arr), ?thisValue)
Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to
thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value
Returns Boolean. Checks if every element in an array pass a test
array.fill(value, start, end)
Returns modified Array. Fill the elements in an array with a static value
array.filter(function(currentValue, index, arr), thisValue)
Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to
thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value
Returns new Array. Creates a new array with every element in an array that pass a test
array.find(function(currentValue, index, arr),thisValue)
Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to
thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value
Returns the value of the first element in an array that pass a test; returns undefined is none pass
array.findIndex(function(currentValue, index, arr), thisValue)
Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to
thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value
Returns the index of the first element in an array that pass a test; if none, returns -1
array.forEach(function(currentValue, index, arr), thisValue)
Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to
thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value
Calls a function for each array element
array.indexOf(item, ?start)
if start negative will count from end and continue to end
Search the array for an element and returns its position
Array.isArray(obj)
Return Boolean. Checks whether an object is an array
array.join(?separator)
if no separator, defaults to comma
Returns String. Joins all elements of an array into a string
array. lastIndexOf(item, ?start)
start: Where to start the search. Negative values will start at the given position counting from the end, and search to the beginning
Search the array for an element, starting at the end, and returns its position
array.map(function(currentValue, index, arr), thisValue)
Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to
thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value
Returns new Array. Creates a new array with the result of calling a function for each array element
array.pop()
Removes the last element of an array, and returns that element, changes original array
array.push(item1, item2, …, itemX)
Adds new elements to the end of an array, and returns the new length