Array Methods Flashcards
some()
tests if at least one element in the array passes the test implemented by the provided function.
Arrow Function example.
arr. some( x => x > 10) arr. some(x => val === x
concat()
returns a new array by merging two or more values/arrays.
filter()
return array with all elements that passed the test defined by the given function.
Does not change the original array.
filter() calls a provided callbackFn function once for each element in an array and constructs a new array of all the values for which callbackFn returns a value that coerces to true.
forEach()
executes a provided function once for each array element.
Does not change the original array.
Does not return anything
only using data
map()
executes a provided function once for each array element.It builds a new Array.
does not change the original array.
reduce()
The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.
(accumulator, currentValue) => accumulator + currentValue;
pop()
remove last item
shift()
remove first item
push()
add item to the end
unshift()
add item to the front
splice()
removes array items and replaces new items if provided
first start
second how many remove including start
we can use negative numbers.
slice()
returns a new array containing the specified items except the last index provided.
slice(beginning, end)
Does not modify existing array
Returns a new array
indexOf()
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
Can be used to check if element is present in the array/
if ( arr.indexOf > -1) {}
lastIndexOf()
returns the last occurrence of the element your searching
return the index of element.
includes()
This method checks if an item is present in the array and returns a Boolean.