DEV Community

[Comment from a deleted post]
Collapse
 
devdrake0 profile image
Si

Appreciate the follow up @brieucp !

I'd argue that array.forEach(console.log) is acceptable in some circumstances. For example, if you're developing a new function and want to see want to log each element for debug purposes.

But generally, in a production setting, logging every element in an array is not good practice regardless of the method you choose.

 
brieucp profile image
brieucp

I wasn't talking about the console.log, I was about the fact that a funny thing happen when you do something like [1,2,3].forEach(console.log) (same with map)

1 0 [ 1, 2, 3 ]
2 1 [ 1, 2, 3 ]
3 2 [ 1, 2, 3 ]

Because forEach and map are passing three params on each call (the element, its index and the full list) which is probably not what you want. It's true with all function that takes more than one input.

 
devdrake0 profile image
Si

Ah I see what point you were making now!

Then yeah, you're obviously correct 😊.

Sorry, I got the wrong end of the stick!