Well, one could say that the arguments are in the same order. If you look at the source code, you will see that in grep, the callback is called like this:
callback( elems[ i ], i ) )
whereas in each (when working with an array, not with a map):
var value = object[0]; callback.call( value, i, value )
where the value is the this object. This method invocation method is used to override the value of this.
Therefore, I suggest that the preferred way to use each is to use this to refer to an object.
In my opinion, this difference is not very good, as it makes the life of users more difficult. I checked and both versions were introduced in version 1.0, so it cannot be justified that this was due to two different opinions.
source share