Lodash Cheatsheet
Lodash Cheatsheet
DEVHINTS.IO Edit
Lodash cheatsheet
Finding Accessing
_.map(list, ...)
Array
Arrays Filtering
_.uniq()
_.without([ abcde ], b) // → [ acde ]
_.difference([ abc ], [ bc ]) // → [ a ]
_.intersection([ abc ], [ bcd ]) // → [ bc ]
_.union([ abc ], [ bcd ]) // → [ abcd ] (unique) _.remove(list, (n) => n % 2)
Indexes
Array#concat()
https://devhints.io/lodash 2/7
6/15/2018 Lodash cheatsheet
_.findIndex(list, fn)
_.findLastIndex(list, fn)
_.sortedIndex(list, val)
_.sortedLastIndex(list, val)
_.indexOf(list, val)
Functions
Currying
fn = _.partial(fn, 'hi')
fn('joe') // → 'hi, joe!'
fn = _.partial(fn, 'joe')
fn('yo') // → 'yo, joe!'
_.curry(greet)('hi') // → function(name)
_.curryRight(greet)('joe') // → function(greet)
https://devhints.io/lodash 3/7
6/15/2018 Lodash cheatsheet
Decorating functions
Throttling Limiting
Etc
_.delay(fn, 2000)
_.negate(fn)
_.memoize(fn)
_.memoize(fn, ...)
Strings
Capitalization Padding
Trim
Etc
_.trim(' str ') // → 'str'
_.repeat('-', 2) // → '--' _.trimLeft(' str ') // → 'str '
_.deburr('déjà vu') // → 'deja vu' _.trimRight(' str ') // → ' str'
_.trunc('hello world', 5) // → 'hello...'
Objects
Keys and values
_.keys(obj)
_.values(obj)
Chaining
https://devhints.io/lodash 5/7
6/15/2018 Lodash cheatsheet
_([1, 2, 3])
.reduce((total, n) => total + n)
.map((n) => n * n)
.tap(console.log)
.thru((n) => n.reverse())
.value()
Devhints home
Yarn bluebird.js Vim scripting Capybara
https://devhints.io/lodash 6/7
6/15/2018 Lodash cheatsheet
https://devhints.io/lodash 7/7