The thisArg argument is irrelevant for any callbackFn defined with an arrow function, as arrow functions don't have their own this binding.Īll iterative methods are copying and generic, although they behave differently with empty slots. The this value ultimately observable by callbackFn is determined according to the usual rules: if callbackFn is non-strict, primitive this values are wrapped into objects, and undefined/ null is substituted with globalThis. ![]() The thisArg argument (defaults to undefined) will be used as the this value when calling callbackFn. What callbackFn is expected to return depends on the array method that was called. The array that the method was called upon. The index of the current element being processed in the array. The current element being processed in the array. Where callbackFn takes three arguments: element The following table lists the methods that mutate the original array, and the corresponding non-mutating alternative: Mutating methodĪn easy way to change a mutating method into a non-mutating alternative is to use the spread syntax or slice() to create a copy first: Conceptually, they are not copying methods either. Group() and groupToMap() do not use to create new arrays for each group entry, but always use the plain Array constructor. The following methods always create new arrays with the Array base constructor:
0 Comments
Leave a Reply. |