Reputation: 2193
Can one do more than the other? Should I stick with lodash or just use ES6's map method?
Upvotes: 8
Views: 10008
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
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
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