Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 15, 2021 10:50 am GMT

Array Methods

An array is a special variable that can hold more than one value at the same time. That is, they are used in Javascript to store multiple values in one variable.

As a programmer, you'll need to adjust/remove/add/replace/count etc elements in an array therefore you need to know the right method to use for any manipulation. There are different methods of manipulating an array and I will be showing some of them.

concat()

This method is used to merge (concatenate) existing arrays. It returns the new array by combining previously declared array variables.
Alt Text

splice()

This method changes the content of an array by adding and/or removing or replacing elements in an array.
Alt Text

every()

This method returns true or false if every element in the specified array satisfies a condition specified in the callback function. Returns false even if a single element does not satisfy the condition.
Alt Text

filter()

This method returns a new array of all elements that satisfy a given condition.
Alt Text

shift()

This method removes the first element of the array. Its return value is the removed element.
Alt Text

pop()

Unlike shift above, the pop() method removes the last element from an array and returns that element.
Alt Text

Other methods include but not limited to:

MethodsMethods
forEachmap()
indexOfreverse()
join()lastIndexOf()
fill()fine()
unshift()toString()

Original Link: https://dev.to/etulan/array-methods-4a2h

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To