Better Programming

Advice for programmers.

Follow publication

Member-only story

10 JavaScript Array Methods To Boost Your Code Performance

Jose Granja
Better Programming
Published in
6 min readApr 5, 2021
open laptop showing code on the screen
Photo by Arnold Francisca on Unsplash

With lots of instance methods, the Array API is one of the biggest in JavaScript. At first, it can be overwhelming. It is important to invest some time in getting familiar with it. Methods like map() and forEach() are widely abused. Instead, by using the right interface you can make your code faster, more efficient, and more readable.

There is something to consider when using array methods: some are immutable and some are mutable. Being aware of what type of method you are using is crucial. Misuse can lead to nasty bugs.

In this article, we will be looking at the ten more useful instance methods of the JavaScript Array object and where they shine.

1. Slice

If you want to make a copy of an array by a start and end index, you might want to use slice(). This method is a pure function so it won’t have any side effects, nor mutate the target array.

“The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.” — MDN

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Jose Granja
Jose Granja

Written by Jose Granja

Top Writer @Medium | 1M+ Views | Lead FE @Lingoda | I write weekly about web-development topics 📰 Support me at https://dioxmio.medium.com/membership 🙇

Write a response