_.flatten(array) //减少一级array嵌套深度。
_.fromPairs([['fred', 30], ['barney', 40]]) //返回{ 'fred': 30, 'barney': 40 }
_.initial(array) //获取数组array中除了最后一个元素之外的所有元素
_.tail(array) //获取数组array中除了第一个元素之外的所有元素
_.last(array) //最后一个元素
_.intersection([2, 1], [2, 3]) //获取交集[2]
_.union([2], [1, 2]) //获取并集[2,1] 从右到左
_.xor([2, 1], [2, 3]) //获取差集[1,3]
_.uniq([2, 1, 2]) //去重
_.reverse(array) //逆序
_.take([1, 2, 3], 2) // => [1, 2]
_.zip(array,array) //按索引合并数组
_.unzip(array) //按索引解压数组
_.zipObject(['a', 'b'], [1, 2]) // => { 'a': 1, 'b': 2 }
_.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
return a + b + c;
}); // => [111, 222] zip with function
collection:(Array|Object)
_.each -> forEach(collection,function(value,index|key){ ... })
_.every(collection,predicate) //返回布尔值,全真为真
_.some(collection, predicate) //返回布尔值,一真为真
_.filter(collection,predicate)
_.reject(,collection,predicate) //!filter
_.flatMap(collection, [iteratee=_.identity])
// function duplicate(n) {
// return [n, n];
// }
// _.flatMap([1, 2], duplicate);
// => [1, 1, 2, 2]
_.groupBy(collection,predicate ) //按谓语进行分组return Object
_.partition(collection, predicate) //按谓语进行分组return Array
_.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); // => [[1, 5, 7], [1, 2, 3]]
_.map([4, 8], function)
// function square(n) {
// return n * n;
// }
//_.map([4, 8], square);
// => [16, 64]
//_.map({ 'a': 4, 'b': 8 }, square);
// => [16, 64] (iteration order is not guaranteed)
// var users = [
// { 'user': 'barney' },
// { 'user': 'fred' }
// ];
// The `_.property` iteratee shorthand.
// _.map(users, 'user');
// => ['barney', 'fred']
_.sample([1, 2, 3, 4]) //// => 2
_.size([1, 2, 3]) // => 3
Date
_.now() //now timestamp
Object
_.assign(object, [sources])
_.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }) //对象合并,从右到左
_.mapKeys(object,function(v,k){ ... })