Skip to content

Lodash Spickzettel

Moderne JavaScript-Utility-Bibliothek mit Modularität und Performance.

01

Einstieg

Import

Vollständige oder benannte Imports.

lodash
import _ from "lodash";
// or
import { map, filter, debounce } from "lodash";

Collection

Collection-Methoden für Arrays/Objekte.

lodash
_.map([1, 2, 3], n => n * 2);   // [2, 4, 6]
_.filter(users, { active: true });
_.find(users, u => u.age > 18);
_.groupBy(users, "role");

Objekte

Utilities zur Objektmanipulation.

lodash
_.pick(obj, ["a", "b"]);    // keep keys
_.omit(obj, ["c"]);         // remove keys
_.merge(obj1, obj2);        // deep merge
_.cloneDeep(obj);           // deep clone
02

Funktionen

Strings

Utilities zur String-Transformation.

lodash
_.camelCase("Foo Bar");     // "fooBar"
_.kebabCase("Foo Bar");     // "foo-bar"
_.capitalize("foo");        // "Foo"
_.truncate("hello world", { length: 5 }); // "he..."

Funktionssteuerung

Funktionssteuerung: debounce, throttle, memoize.

lodash
const debounced = _.debounce(fn, 300);
const throttled = _.throttle(fn, 100);
const memoized = _.memoize(expensiveFn);

Arrays

Utilities zur Array-Manipulation.

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

Utilities zur Typ- und Sprachprüfung.

lodash
_.isEqual(obj1, obj2);     // deep equality
_.isEmpty([]);             // true
_.isNil(null);             // true
_.isNumber(42);            // true

Was this helpful?