lodash started out as a fork of the Underscore.js library because it disagrees with other (Underscore.js) contributors. John-David Dalton's initial goal was to provide more "consistent cross-browser behavior... and improve performance". After that, the project achieved even greater results on the existing success and released version 3.0 in January.
Let me tell you about javascript lodash knowledge, the specific details are as follows:
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//The output has no 0 false space
2_.different usage
var test = _.difference([1, 2, 3, 4, 5], [5, 2, 10]);console.log(test);1,3,4//The output result is that the first array has the second array without
3_.find usage
var characters = [{ 'name': 'barney', 'age': 36, 'blocked': false },{ 'name': 'fred', 'age': 40, 'blocked': 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) { // (intermediate code omitted) The intermediate assumption is to change a property in the active object found by the loop, such as status, change its value to 0; } Replace _.find(activity,function(activity){ return activity.name == bidList[0].activityName}).status = 0; //In this way, we find the corresponding object through find and change the value4 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; }After replacement
_.map(a,function(num){ return num = num + 1; })5. After replacing for, replace if
var a; if(activities.length){ a = 1; } if(!activities.legth){ a = 0; }After replacement
var a = activities.length ? 1 : 0;
The above is a series of common usages of JavaScript lodash introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!