Funk Soul Ninja
Funk Soul Ninja

Reputation: 2193

What are the differences between the map methods in ES6 and lodash?

Can one do more than the other? Should I stick with lodash or just use ES6's map method?

Upvotes: 8

Views: 10008

Answers (3)

eugene
eugene

Reputation: 41725

lodash can handle undefined

let a = undefined

_.map(a, (e) => {console.log("hello")})
// vs    
a.map((e) => {console.log('this is an error')}). //undefined error 

Upvotes: 7

erikvdplas
erikvdplas

Reputation: 551

Besides @georg's comment on the possibility of using lodash _.map as a shorthand for _.property, lodash map can be used for any iteratable, whereas ES6 map can only be used for arrays.

Upvotes: 10

matanso
matanso

Reputation: 1292

They're both compliant with the ECMA-262 spec, so they're identical. However, for portability (and perhaps performance/readability), I personally prefer the built-in ES6 map method.

Upvotes: 6

Related Questions