lodash笔记

https://lodash.com/docs

lodash包括以下几个模块:

  1. Array
  2. Collection
  3. Date
  4. Function
  5. Lang
  6. Math
  7. Number
  8. Object
  9. Seq
  10. String
  11. Util
  12. Properties
  13. Methods

重要方法

Array
_.findIndex(array, [predicate=_.identity], [fromIndex=0])
_.indexOf(array, value, [fromIndex=0])
_.intersection([arrays])
_.join(array, [separator=','])
_.last(array)
_.pull(array, [values])
_.remove(array, [predicate=_.identity])
_.slice(array, [start=0], [end=array.length])
_.union([arrays])

Collection
_.countBy(collection, [iteratee=_.identity]) 按属性计数
_.filter(collection, [predicate=_.identity]) 返回数组
_.every(collection, [predicate=_.identity])
_.find(collection, [predicate=_.identity], [fromIndex=0]) 返回第一个匹配
_.forEach(collection, [iteratee=_.identity])
_.map(collection, [iteratee=_.identity])
_.reduce(collection, [iteratee=_.identity], [accumulator])
_.orderBy(collection, [iteratees=[_.identity]], [orders])
_.sample(collection) 随机选取
_.size(collection)
_.some(collection, [predicate=_.identity])
_.sortBy(collection, [iteratees=[_.identity]])

Lang
_.clone(value)
_.cloneDeep(value)
_.eq(value, other)
_.isEqual(value, other)


Math
_.max(array)
_.maxBy(array, [iteratee=_.identity])
_.mean(array)
_.meanBy(array, [iteratee=_.identity])
_.sum(array)
_.sumBy(array, [iteratee=_.identity])

Number
_.random([lower=0], [upper=1], [floating])

String
_.padStart([string=''], [length=0], [chars=' '])
_.parseInt(string, [radix=10])
_.repeat([string=''], [n=1])
_.replace([string=''], pattern, replacement)
_.truncate([string=''], [options={}], [options.length=30], [options.omission='…'], [options.separator])
_.split([string=''], separator, [limit])
_.startsWith([string=''], [target], [position=0])
_.trim([string=''], [chars=whitespace])
_.pad([string=''], [length=0], [chars=' '])
_.over([iteratees=[_.identity]])
_.overEvery([predicates=[_.identity]])
_.overSome([predicates=[_.identity]])
_.property(path)
_.propertyOf(object)
_.range([start=0], end, [step=1])
_.times(n, [iteratee=_.identity])
_.uniqueId([prefix=''])