Ayesha Malik
1 min readNov 21, 2022

--

Array.prototype.map returns a new array containing the results of calling a given function on every element of the calling array.

callbackFn: A function to execute for each element in the array. Its return value is added as a single element in the new array.

Pollyfill for map

  • Passing the index and array to the map callback.
  • Calling the map callback with the correct this if thisArg is specified.
  • Sparse arrays (e.g. [1, 2, , 4]). The empty values should be ignored while traversing the array.
  • The thisArg doesn't do anything if the callback is defined as an arrow function as arrow functions don't have their own bindings to this.

Resources

--

--

Ayesha Malik

I’m a full-time software engineer who loves sharing knowledge to help others become better developers.