1// import entire library
2import _ from "lodash"
3const nums = [1, 2, 2, 3, 1, 4]
4let res = _.uniq(nums)
5
6// import methods by name
7// Still loads entire lodash library!!
8import { uniq } from "lodash"
9const nums = [1, 2, 2, 3, 1, 4]
10let res = uniq(nums) // better readability
11
12// import only what you need
13import uniq from "loadash/uniq"
14const nums = [1, 2, 2, 3, 1, 4]
15let res = uniq(nums)
16
1var users = [
2 { 'user': 'barney', 'age': 36, 'active': true },
3 { 'user': 'fred', 'age': 40, 'active': false },
4 { 'user': 'pebbles', 'age': 1, 'active': true }
5];
6
7_.find(users, function(o) { return o.age < 40; });
8// => object for 'barney'
1var object = { 'a': 1, 'b': '2', 'c': 3 };
2
3_.pick(object, ['a', 'c']);
4// => { 'a': 1, 'c': 3 }
1import merge from 'lodash/merge'
2
3let object = { 'a': [{ 'b': 2 }, { 'd': 4 }]};
4let other = { 'a': [{ 'c': 3 }, { 'e': 5 }]};
5merge(object, other); // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
1var users = [
2 { 'user': 'barney', 'age': 36, 'active': true },
3 { 'user': 'fred', 'age': 40, 'active': false }
4];
5
6_.filter(users, function(o) { return !o.active; });
7// => objects for ['fred']
8
9// The `_.matches` iteratee shorthand.
10_.filter(users, { 'age': 36, 'active': true });
11// => objects for ['barney']
12
13// The `_.matchesProperty` iteratee shorthand.
14_.filter(users, ['active', false]);
15// => objects for ['fred']
16
17// The `_.property` iteratee shorthand.
18_.filter(users, 'active');
19// => objects for ['barney']