码迷,mamicode.com
首页 > 其他好文 > 详细

lodash常用方法2--修改

时间:2016-12-17 22:14:38      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:back   var   call   rate   sso   ons   ack   iss   返回   

1.map

function timesThree(n) {
  return n * 3;
}

_.map([1, 2], timesThree);
// => [3, 6]

  

2.remove

移除数组 array 中满足 predicate 条件的所有元素 ,返回的是被移除元素数组. 

var array = [1, 2, 3, 4];
var evens = _.remove(array, function(n) {
  return n % 2 == 0;
});

console.log(array);
// => [1, 3]

console.log(evens);
// => [2, 4]

  

3.uniq

唯一

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

// using `isSorted`
_.uniq([1, 1, 2], true);
// => [1, 2]

// using an iteratee function
_.uniq([1, 2.5, 1.5, 2], function(n) {
  return this.floor(n);
}, Math);
// => [1, 2.5]

// using the `_.property` callback shorthand
_.uniq([{ ‘x‘: 1 }, { ‘x‘: 2 }, { ‘x‘: 1 }], ‘x‘);
// => [{ ‘x‘: 1 }, { ‘x‘: 2 }]

  

lodash常用方法2--修改

标签:back   var   call   rate   sso   ons   ack   iss   返回   

原文地址:http://www.cnblogs.com/ganchuanpu/p/6192977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!