lodash官方文档总结

lodash官方中文文档:https://www.css88.com/doc/lodash/

Array

     _.chunk   (一个数组在内部分割出两个数组,可以指定第一个数组的参数个数)

_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
 
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]

 _.compact (去除一个数组中的 0 false 和空值)

_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]

_.concat(将里面的所有的数组合并到新的大数组中,如果元素本身是数组,则解除一层数组,如果是正常数字则不动)

var array = [1];
var other = _.concat(array, 2, [3], [[4]]);
 
console.log(other);
// => [1, 2, 3, [4]]
 
console.log(array);
// => [1]

_.difference(将两个作为参数的数组比较,取出不相同的元素,组成新的数组)

_.difference([2, 1], [2, 3]);
// => [1]

_.differenceWith(返回出前一个对象中和已有对象中不同的那个)

var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
 
_.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
// => [{ 'x': 2, 'y': 1 }]

_.drop(从尾部删除几个元素,默认是一个) 

_.drop([1, 2, 3]);
// => [2, 3]
 
_.drop([1, 2, 3], 2);
// => [3]
 
_.drop([1, 2, 3], 5);
// => []
 
_.drop([1, 2, 3], 0);
// => [1, 2, 3]

_.dropRight(反过来)

_.dropRight([1, 2, 3]);
// => [1, 2]
 
_.dropRight([1, 2, 3], 2);
// => [1]
 
_.dropRight([1, 2, 3], 5);
// => []
 
_.dropRight([1, 2, 3], 0);
// => [1, 2, 3]

猜你喜欢

转载自blog.csdn.net/qq_41619567/article/details/84789311