5 Useful Javascript Array Methods and How to Use Them

Felix Rodriguez
3 min readJun 24, 2020

Arrays are some of the most commonly used objects in Javascript. I have found myself using arrays more often than not. If you are reading this then I suspect the same is true for you.

Manipulating arrays in javascript is something every beginner needs to familiarize themselves with right away.

In this article I am going to go over five of the most useful array functions I have found so far in my process of learning JS. So lets begin..

Array.from()

This function is probably one of the most useful in my opinion. In javascript there are lots of array-like objects that are not exactly arrays. This function allows you to create a new array from said object. From there you can use the all the powerful functions that an array has to offer.

forEach()

The forEach function is next up. This function allows you to iterate through an array and perform an action on each item in that array. This could be accomplished with a simple for loop but this function makes your code look cleaner and less verbose. In this example we take a simple array of numbers and add 1 to each number and display it in the console. The original array remains unchanged. Let’s take a look..

map()

This is a function requires that you pass in a callback function. This callback function can be defined as it is being passed in or anywhere else. The map() function then iterates through the array and invokes the callback function on each item. A new mutated array is then returned. We can see how this works below..

find()

It is super useful to be able to extract an item from an array based on some condition. Here is where this function comes into play. By passing in a function that checks for some condition you will get the first item in the array that matches that condition.

sort()

This function is a bit more tricky than the rest and probably needs its own article but here are the basics. The sort function can accept a callback function as an argument but does not require it. If no callback function is provided it will just sort the items in the array based on converting them to strings and comparing their unicode order. More info on that can be found here. The original array is altered and arranged in the new order. For example:

Again things get a little tricker when you decide to pass in your own comparison callback function. If your looking for more information on how to do that or just a more in-depth explanation of how the sort() function works there is a great resource located here.

These are just some of the array methods that have been a big help in manipulating data in my javascript programs. If your looking for more information these functions you can always check out the mozilla developer network page on Array Methods. Hope this helps!

--

--