JavaScript Array Methods. (Part-2)
JavaScript Array Methods. (Part-2)
Array Methods
Finding elements
High-order methods
Part-2
Finding elements
indexOf()
To find the position of an element in an
array, you use the indexOf() method.
This method returns the index of the
first occurrence the element that you
want to find, or -1 if the element is not
found.
Finding elements
includes()
The includes() method returns true if an
array contains a given element;
Otherwise, it returns false.
ECMAScript 2016 standardized this functionality by
providing the Array.prototype.includes() method.
Finding elements
find()
findIndex()
map()
filter()
The filter() method of array instances
creates a shallow copy of a portion of a
given array, filtered down to just the
elements from the given array that pass the
test implemented by the provided function.
High-order methods
reduce()
The reduce() method of array instances
executes a user-supplied "reducer" callback
function on each element of the array,in
order, passing in the return value from the
calculation on the preceding element. The
final result of running the reducer across
all elements of the array is a single value
High-order methods
every()
The every() method of Array instances tests
whether all elements in the array pass the
test implemented by the provided function.
It returns a Boolean value.
High-order methods
some()
The some() method of Array instances tests
whether at least one element in the array
passes the test implemented by the
provided function. It returns true if, in the
array, it finds an element for which the
provided function returns true; otherwise it
returns false. It doesn't modify the array.
High-order methods
sort()
The sort() method of Array instances sorts
the elements of an array in place and
returns the reference to the same array,
now sorted. The default sort order is
ascending, built upon converting the
elements into strings, then comparing their
sequences of UTF-16 code units values.
High-order methods
forEach()
The forEach() method of Array instances
executes a provided function once for each
array element.