The following code works:
let _ = require('lodash');
let arr= _([1,2,3,4]);
let b = arr.map((e)=>e^2);
The following does not work:
let chain = require('lodash/chain');
let arr= chain([1,2,3,4]);
let b = arr.map((e)=>e^2);
It gives me the following error:
arr.map is not defined.
Is there a way to use chain without importing the whole global object?
The Lodash _. chain() method used to wrap the value with explicit method chain sequences enabled.
While lodash offeres a tremendous library of functionality, much of it is no longer required, and the cost of importing lodash into your application can be huge, well over 600kb if your compiler doesn't shake the unrequired code, or you use lodash throughout your application.
How to correctly include specific functions of the popular lodash library in your web JavaScript project without having to import the entire library. Lodash is an extremely popular JavaScript library that provides a lot of useful functions for working with strings, arrays and objects in your web projects.
You need at least core
:
var _ = require('lodash/core');
let arr= _([1,2,3,4]);
let b = arr.map((e)=>e^2);
You can also roll your own custom lodash package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With