JavaScript Array Methods to Make You a Better Developer

Paige Niedringhaus
7 min readApr 30, 2018

Back when I began my new career as a web developer, the fact that I could loop through an array of objects in JavaScript was very cool.

The classic for loop, it will always have its place, but there’s a world of other array methods just waiting to be utilized in JavaScript. The right tool for the right job is what I’m constantly trying to keep in mind when solving problems.

Now, having worked at it for almost 2 years, I’ve learned a heck of a lot more, including some much more sophisticated methods for manipulating arrays, which I’d like to share today.

One more thing I’d like to add before diving in, is that, in general, it tends to be a better practice not to alter existing arrays or objects. If you mutate the original item, you run the risk of unforeseen side effects: wherever else in the code that array or object is referenced, the mutated result could be used instead. This can make finding the root cause of a bug caused by the mutated code more difficult than it needs to be, to say the least.

Therefore, the methods I cover are known as pure functions, because instead of changing the original array, they instead make a copy and make the changes to that copy and return it to the scope outside of the method as a new array. Just something to keep in mind as you read through this article.

Map

The first method that will come in extremely handy is Array.map(). The map method takes in an array, and creates a new array with the results of calling a function for every element in that…

--

--

Paige Niedringhaus
Paige Niedringhaus

Written by Paige Niedringhaus

Staff Software Engineer at Blues, previously a digital marketer. Technical writer & speaker. Co-host of Front-end Fire & LogRocket podcasts

Responses (1)