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 arra…


This content originally appeared on DEV Community and was authored by Etulan

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()


This content originally appeared on DEV Community and was authored by Etulan


Print Share Comment Cite Upload Translate Updates
APA

Etulan | Sciencx (2021-04-15T10:50:35+00:00) Array Methods. Retrieved from https://www.scien.cx/2021/04/15/array-methods/

MLA
" » Array Methods." Etulan | Sciencx - Thursday April 15, 2021, https://www.scien.cx/2021/04/15/array-methods/
HARVARD
Etulan | Sciencx Thursday April 15, 2021 » Array Methods., viewed ,<https://www.scien.cx/2021/04/15/array-methods/>
VANCOUVER
Etulan | Sciencx - » Array Methods. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/15/array-methods/
CHICAGO
" » Array Methods." Etulan | Sciencx - Accessed . https://www.scien.cx/2021/04/15/array-methods/
IEEE
" » Array Methods." Etulan | Sciencx [Online]. Available: https://www.scien.cx/2021/04/15/array-methods/. [Accessed: ]
rf:citation
» Array Methods | Etulan | Sciencx | https://www.scien.cx/2021/04/15/array-methods/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.