lodash size code example
Example 1: import lodash
import _ from "lodash"
const nums = [1, 2, 2, 3, 1, 4]
let res = _.uniq(nums)
import { uniq } from "lodash"
const nums = [1, 2, 2, 3, 1, 4]
let res = uniq(nums)
import uniq from "loadash/uniq"
const nums = [1, 2, 2, 3, 1, 4]
let res = uniq(nums)
Example 2: how to loop through an object using lodash
_.forOwn(obj, function(value, key) { } );
Example 3: lodash deep clone object
const clone = require('lodash/clone');
const cloneDeep = require('lodash/clonedeep');
const shallowCopy = clone(originalObject);
const deepCopy = clonedeep(originalObject);
Example 4: Lodash remove duplicates from array
var users = [
{id:1,name:'ted'},
{id:1,name:'ted'},
{id:1,name:'bob'},
{id:3,name:'sara'}
];
var uniqueUsersByID = _.uniqBy(users,'id');
var uniqueUsers = _.uniqWith(users, _.isEqual);