Array Methods
Array Methods
Array Methods
Array Methods
()
A comprehensive guide
Divyansh Tripathi
Overview
Divyansh Tripathi
Common Array methods
.slice() .includes()
.splice() .concat()
.forEach() .sort()
.map() .some()
Divyansh Tripathi
.push() & .pop()
.push(): Adds one or more elements to the end
of an array and returns the new length of the
array.
Divyansh Tripathi
.shift() & .unshift()
.shift(): Removes the first element from an array
and returns that element.
Divyansh Tripathi
.splice()
Divyansh Tripathi
.forEach()
Divyansh Tripathi
.map()
.map(): creates a new array by applying a
provided function to each element of an
existing array. It does not change the original
array; instead, it returns a new array where each
element is the result of the function applied to
the corresponding element in the original array.
Divyansh Tripathi
.filter()
.filter(): Creates a new array filled with
elements that pass a test provided by a
function. It iterates over each element in the
original array, applying the test (callback
function) to each element.
Divyansh Tripathi
.reduce()
.reduce(): Executes a reducer function on each
element of the array, resulting in a single output
value. Syntax:
Example:
Divyansh Tripathi
.find() & .findIndex()
.find(): Returns the value of the first element in
the array that satisfies the provided testing
function. If no values satisfy the testing
function, undefined is returned.
Divyansh Tripathi
.includes() & .concat()
.includes(): Determines whether an array
includes a certain value among its entries,
returning true or false.
Divyansh Tripathi
.sort()
.sort(): Sorts the elements of an array in place and
returns the array. The default sort order is built upon
converting the elements into strings, then comparing
their sequences of UTF-16 code units values.
Divyansh Tripathi
.reverse(), .join(), .split()
.reverse(): Reverses the order of the elements in an
array in place and returns the array.
Divyansh Tripathi
.some()
.some(): Checks if at least one element in the array
passes a test (provided as a function). If it finds an
element for which the provided function returns true, it
immediately returns true and stops. Otherwise, it
returns false.
Divyansh Tripathi
.every()
.every(): Checks if all elements in the array pass a test
(provided as a function). If all elements pass the test, it
returns true. If any element fails the test, it returns
false and stops.
Divyansh Tripathi
Combining Array Methods for
Powerful Data Manipulation
Array methods can be chained together to perform
complex data manipulations with minimal code.
Here is an example:
You have an array named products that contains
objects representing different products. Each product
has a name, price, and inStock status.
Divyansh Tripathi
Explanation:
Divyansh Tripathi
I hope you found this material
useful and helpful.
Remember to:
Like
&
Share with your network, be
helpful to someone 👌
Divyansh Tripathi
Hi There!
Thank you for reading through
Did you enjoy this knowledge?
Divyansh Tripathi