DEV Community

Panda Quests
Panda Quests

Posted on

What are reasons not to use native array manipulation functions in JavaScript, e.g. map, filter, reduce, some, every, etc?

Top comments (1)

Collapse
 
timhlm profile image
moth

There's no golden rule, each of these are a different tool the should be used at the right time.

Do you want a new instance of an array after your manipulation, without editing the original? You should use map, filter, reduce, etc. Since these are creating new instances of arrays during their computation, they should be avoided during uses cases of extreme space/time requirements.

Do you need to edit an array in place? For loops with push/pop is a fine solution.

The only one I generally do not use is .forEach. I think a for...of is more readable.

Arrays in general among the most powerful tools in JS. We should be leveraging these to their full extent!