DEV Community

Discussion on: .map() Polyfill

Collapse
 
lexlohr profile image
Alex Lohr

Your polyfill deviates from standard behavior regarding sparse Arrays. Compare

[1,,3].map(console.log)
// only logs existing items
[1,,3].myMap(console.log)
// also logs the empty item
Enter fullscreen mode Exit fullscreen mode

Use for..in and check for hasOwnProperty to rectify that issue.