整理lodash 10个常用方法
- _.cloneDeep(object) 深度克隆一个对象,创建一个深度克隆的对象副本。
- _.isEmpty(value) 检查传入的值(value)是否为空。如果是空的,返回true;否则返回false。
- _.get(object, path, [defaultValue]) 从对象(object)中获取指定路径(path)对应的值。如果路径不存在,则返回默认值(defaultValue)。
- _ .groupBy(collection, [iteratee=.identity]) 对集合(collection)中的元素进行分组,分组的依据是iteratee处理后的结果。如果iteratee没有传入,则默认使用元素的值进行分组。
- .orderBy(collection, [iteratees=[.identity]], [orders]) 对集合(collection)进行排序。可以传递一个或多个排序条件,以及每个排序条件的排序方式。
- .filter(collection, [predicate=.identity]) 遍历(collection)中的元素,保留满足条件(predicate)的元素,返回符合条件的一个新数组。
- .map(collection, [iteratee=.identity]) 遍历集合(collection)的每个元素,并用iteratee处理(each element of collection)返回处理后的元素组成的数组。
- .reduce(collection, [iteratee=.identity], [accumulator]) 遍历集合(collection)的每个元素,并用iteratee处理,返回处理后的结果累加起来,形成accumulator。
- .find(collection, [predicate=.identity], [fromIndex=0]) 遍历集合(collection),返回第一个符合条件(predicate)的元素;如果没有符合条件的,则返回undefined。
- _.debounce(func, [wait=0], [options={}]) 返回一个debounced函数,debounced函数会延迟执行func函数并限制func函数频率,wait参数表示等待延迟的时间。