01
Getting Started
Import
Full or named imports.
lodash
import _ from "lodash";
// or
import { map, filter, debounce } from "lodash";Collection
Collection methods for arrays/objects.
lodash
_.map([1, 2, 3], n => n * 2); // [2, 4, 6]
_.filter(users, { active: true });
_.find(users, u => u.age > 18);
_.groupBy(users, "role");Object
Object manipulation utilities.
lodash
_.pick(obj, ["a", "b"]); // keep keys
_.omit(obj, ["c"]); // remove keys
_.merge(obj1, obj2); // deep merge
_.cloneDeep(obj); // deep clone02
Features
String
String transformation utilities.
lodash
_.camelCase("Foo Bar"); // "fooBar"
_.kebabCase("Foo Bar"); // "foo-bar"
_.capitalize("foo"); // "Foo"
_.truncate("hello world", { length: 5 }); // "he..."Function
Function control: debounce, throttle, memoize.
lodash
const debounced = _.debounce(fn, 300);
const throttled = _.throttle(fn, 100);
const memoized = _.memoize(expensiveFn);Array
Array manipulation utilities.
lodash
_.chunk([1, 2, 3, 4], 2); // [[1,2], [3,4]]
_.uniq([1, 1, 2, 3, 3]); // [1, 2, 3]
_.flatten([[1, 2], [3]]); // [1, 2, 3]
_.zip([1, 2], [3, 4]); // [[1,3], [2,4]]Lang
Language/type checking utilities.
lodash
_.isEqual(obj1, obj2); // deep equality
_.isEmpty([]); // true
_.isNil(null); // true
_.isNumber(42); // trueWas this helpful?