1 _.compact usage _.compact ([0, 1, False, 2, ', 3, ' mm ']);
var test = _. Compact([ -1,0, 1, False, 2, ', 3, ' JJ ']); Console.log (test);----1,1,2,3,jj//output
2_.different usage
var test = _.difference ([1, 2, 3, 4, 5], [5, 2, ten]); Console.log (test); 1,3,4//output Results
3_.find usage
var characters = [ {' name ': ' Barney ', ' age ': $, ' blocked ': false}, {' name ': ' Fred ', ' age ': +, ' Blocke d ': true}, {' name ': ' Pebbles ', ' age ': 1, ' blocked ': false}];_.find (characters, function (CHR) { console . log (chr.age); return Chr.age < 40;}); Find
for (var n = 0; n < activities.length; n++) { if (activities[n].name = = bidlist[0].activityname) { //(middle code omitted) middle The assumption is to change a property in the object of the activity found by the loop, such as status, to change its value to 0; } Replace the _.find (activities,function (activity) {return activity.name = = Bidlist[0].activityname}) with the _.find method. Status = 0;
4 Use Map to remove some for loops
var a = [0,1,2,3,4] for (var i = 0;i < a.length;i++) { a[i] = a[i]+1; }
Replace later
_.map (a,function (num) { return num = num + 1; })
5 Replace for after replace if
var A; if (activities.length) { a = 1; } if (!activities.legth) { a = 0; }
Replace later
Refactoring also has a lot of knowledge, now only use their own to comb them, and then continue to summarize.
The above describes the JavaScript Lodash usage summary, including the aspects of the content, I hope the JavaScript tutorial interested in a friend helpful.
Some functions of Nodejs Lodash