What happened to Lodash _.pluck?
_.pluck
has left the Lodash building in v4.0.0. In its stead, _.map
with property shorthand comes in, suave and effortless, giving you the functionality you need in fewer characters.
Example for the legends. Let's get users' ages:
Travel light with the Lodash Changelog as it directs you from old roads to new bridges. While we're on a roll, the Lodash documentation awaits with a treasure trove of information, useful when that migration itch strikes.
Going native: ES6 alternatives
Lodash: a treasure trove of utilities, but with ES6 arrow functions pulling ahead, some methods can feel, well, antique. Presenting the native JavaScript way:
This approach coexists with modern JavaScript coding standards. It makes reliance on external libraries optional, not mandatory.
The ghost of _.pluck: Extending Lodash with _.mixin
Old habits die hard, and if _.pluck
was your go-to, resurrection is around the corner by using _.mixin
like so:
Embrace the spirit of _.pluck
by extending its functionality to the new realm with a custom pluck
method.
Staying in the loop: Library updates
Adapting is key to survival in a coding world. Libraries evolve, syntax becomes concise, and performance matter. Keep a keen eye on library updates and improve your code for the better.
Choosing ES6 map over Lodash
When does ES6 map
outweigh Lodash?
- You want simple array transformations, sans deep cloning.
- Working with native arrays and crave chainability without summoning Lodash.
- Performance optimization cravings? V8's got you covered with optimizations for native functions.
Heads-up: Potential issues
Watch out when migrating from _.pluck
to _.map
:
- Ensure property names sit consistently across objects, as
_.pluck
plays ostrich with missing properties. - Reimagining objects into another shape? Go verbose with
_.map
, adding clarity over shorthand.
References
Was this article helpful?