文章目录
-
- 安装及文档
- 数组操作
-
-
- _chunk(array, number)
- _.compact(array)
- _concat(array, [value])
- _.difference(array, [values])
- _difference(array, [values],iteratee)
- _.drop(array, number)
- _.dropRight
- _.fill(array, value, start, end)
- _.fromPairs(pairs)
- _take(array, number)
- _.inital(array)
- _union(array)
- _unionBy(array, iteratee)
- _.uniq(array)
- _.uniqBy(array, iteratee)
-
- 集合
- 例子
安装及文档
Npm安装:npm install lodash --save
全局引用:import _ from lodash
中文文档:lodash中文文档
数组操作
_chunk(array, number)
将数组转化为长度为number数组的数组
_.chunk(['a', 'b', 'c', 'd', 'e'],3)
// => [['a', 'b', 'c'], [ 'd', 'e']]
_.compact(array)
对数组的处理,去除数组中的false,null,‘’,undefine,NaN
_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
_concat(array, [value])
返回一个旧数组和value组成的新数组
var array = [1]
var other = _.concat(array, 2, [3], [[4]])
// other => [1, 2, 3, [4]]
_.difference(array, [values])
返回的array中不含values中的值
// (A-(A和B的交集))
_.difference([3, 2, 1], [4, 2]);
// => [3, 1]
_difference(array, [values],iteratee)
返回过滤后的新数组array
_.differenceBy([{
'x': 2 }, {
'x': 1 }], [{
'x': 1 }], 'x')
// => [{ 'x': 2 }]
_.drop(array, number)
切除数组前面number长度的数组,返回后面的数组,默认长度1
_.drop([1, 2, 3]);
// => [2, 3]
_.drop