Often used of Array Methods for JavaScript

Tomlai
3 min readMar 12, 2021

--

Not only in the project but also in some algorithm questions, we will have to use array methods to solve the problem. Array methods are functions built-in to JavaScript that we can apply to our array. Each method has a unique function that performs a change or calculation for our arrays. Of course our good old friend For…In , While…. Loop will work as well. But in many cases array methods will make our answer or solution looks a lot cleaner and easier to read. There are some JavaScript array methods me personally see and use them more often than others.

JavaScript Array Methods

forEach()

This method loop over array by executing a provided callback function for each element in an array.

Map()

This method will create a new array with the results of calling a provided function on every element in the calling array.

Pop()

This method can delete the last element of the array and return its content.

Shift()

This method can delete the first element of the array and return that content.

Unshift()

This method add the elements to the begin of the array and return the new length.

Push()

This method add elements to the end of array and return the new result of array.

Filter()

This method will only let the elements that passed the condition into the new array.

Sort()

This method sort out each element either in ascending or descending order.

toString()

This method converts an array to string and return the result

Reverse()

This method inverts the order of the array elements. Front to back and back to front.

Conclusion

These array methods just my personal preference, for sure there are more array methods others may think they are more useful and better. But as long as we use them more often and have better understand. The array methods will make our work easier and better.

--

--