Lodash (i) just studied the various methods in the array, followed by the frequently used loop traversal problem
1._.forEach(collection, [iteratee=_.identity], [thisArg]) 遍历
_.foreach ([22,33,11,55],function (value) {// If a parameter is returned is its value console.log (value) ; // the }); _.foreach ([22,33,11,55],function (value,index) {// = This is the first parameter that returns the value, The second parameter is subscript index console.log (value); });
2.
_.sortBy(collection, [iteratee=_.identity], [thisArg]) 排序匿名函数+字符串
var arr = [{name: ' BB ', AGE:23
}, {name: ' AA ', Age:22
}];
var arrsortresult = _.sortby (arr,
function
return Item.name; }); _.foreach (Arrsortresult, function (item) {Console.log (item.name); // aa BB });
var strsortresult = _.sortby (' CDA '). Join ('); // the Join () method method is used to put all the elements in an array into a string. The elements are delimited by the specified delimiter. Console.log (strsortresult); ACD
3._.sortedIndex(array, value, [iteratee=_.identity], [thisArg])
参数:array
(Array): The array to be checked value
(*): The parameters to be inserted [iteratee=_.identity]
(function| object|string): Traversal method [thisArg]
(*): iteratee
The bound value
var collection = [' A ', ' B ', ' C ', ' d ', ' F ']; Console.log (' before: ' + collection.join (')); // Before:a b c D F var tobeinserted = ' E '; var sortedindex = _.sortedindex (collection, tobeinserted); Console.log ("This is Sortedindex:" +sortedindex); // This is sortedindex:4 Collection.splice (sortedindex, 0, tobeinserted); Console.log (' after: ' + collection.join (') '); // after:a b c d E F
Just a brief look about the Lodash part, but found that using it can quickly solve their own problems encountered before, I hope that the future work can be applied freely.
Lodash (ii) object + loop traversal + sort