DEV Community

Cover image for Array Methods
Etulan
Etulan

Posted on

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:

Methods Methods
forEach map()
indexOf reverse()
join() lastIndexOf()
fill() fine()
unshift() toString()

Top comments (0)