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.
splice()
This method changes the content of an array by adding and/or removing or replacing elements in an array.
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.
filter()
This method returns a new array of all elements that satisfy a given condition.
shift()
This method removes the first element of the array. Its return value is the removed element.
pop()
Unlike shift above, the pop() method removes the last element from an array and returns that element.
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
Etulan | Sciencx (2021-04-15T10:50:35+00:00) Array Methods. Retrieved from 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.