Arrays Flashcards
Array.concat() ?
Parameters?
Returns?
used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
parameters: as many values (arrays) as you want
new Array instance
Array.every() ?
Parameters?
Returns?
tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
parameters: callbackFn - element, index (optional), array (optional)
bool
Array.at(index)
takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.
returns element || undefined
arr = [1,2,3,4];
arr.length = 1;
What is length doing?
Truncating the array to one element
Array.length does what?
Returns the number of elements in the array (1 indexed)
Array.filter() ?
Parameters?
Returns?
creates a new array with all elements that pass the test implemented by the provided function
parameters: callbackFn that accepts - an element, index (optional), array (optional)
new filtered Array instance
Array.find() ?
Parameters?
Returns?
returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned
parameters: callbackFn that accepts - an element, index (optional), array (optional)
element || undefined
Array.findIndex() ?
Parameters?
Returns?
returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test
parameters: callbackFn that accepts - an element, index (optional), array (optional)
index of the first element in the array that passes the test || -1.
Array.flat() ?
Parameters?
Returns?
creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
parameters: depth
new array with the sub-array elements concatenated into it
Array.flatMap() ?
Parameters?
Returns?
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. It is identical to a map() followed by a flat() of depth 1, but slightly more efficient than calling those two methods separately.
parameter: callbackFn which takes a current element, index, the array
new array with each element being the result of the callback function and flattened to a depth of 1
Array.forEach() ?
Parameters?
Returns?
executes a provided function once for each array element
parameters: callbackFn(element,index, the array)
undefined. doesn’t return anything just runs the function on each element.
Array.from() ?
Parameters?
Returns?
static method creates a new, shallow-copied Array instance from an array-like or iterable object.
parameters: An array-like or iterable object to convert to an array, (optional) map fn
new array instance
Array.includes() ?
Parameters?
Returns?
determines whether an array includes a certain value among its entries,
parameters: searchElement, (optional) fromIndex
* * method is case sensitive **
returns bool
Array.indexOf() ?
Parameters?
Returns?
returns the first index at which a given element can be found in the array
parameters: searchElement, (optional) fromIndex
returns first index of the element in the array or -1
Array.join() ?
Parameters?
Returns?
creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string
parameters: (optional) separator
returns A string with all array elements joined