DEV Community

loading...

8 must-know JavaScript Array Methods in 6 minutes

comscience profile image kapeel kokane ・2 min read

Hi There!

In today's article, we will cover a few essential JavaScript Array Methods which are absolutely essential in one's journey to becoming an advanced level JS dev. Here goes:

Push | Pop | Shift | Unshift

Well, most of us are aware of the Javascript push() method, but there are also the not so well known pop(), shift(), and unshift() methods as well. Check those out in under a minute:

Reduce

Next up is the reduce method. I have seen several developers abuse logic and invent their own algorithms with new variables in order to accomplish something that could be done with a simple reduce() call. Make sure you know this one:

Includes

Instead of checking for the index of a particular item and checking if it is equal to -1 or not, next time around you could use the inbuilt includes() method that does just the job:

Find

Same is the case with find. Instead of looping over all the array items and then manually comparing each one of them with the one to be found, use the find() method and spend the time saved on that on some video games if you like:

Filter

And lastly the filter function. I have seen code wherein a new empty array is created, and then the main array is looped over and checked for a condition while adding to the new array if the condition satisfies. Trust me, the filter() method is a lifesaver:

And that is all for today's post. If you liked that and are interested in getting updates the day I post them and not in an aggregated post like this, then follow me on Twitter:

Cheers! 🙌🏾

Discussion (1)

Collapse
angelomiranda profile image
lt

nice article. i made some videos as well and would like to include it here for more optional references on the topic.



Forem Open with the Forem app