Lodash (ii) object + loop traversal + sort

Source: Internet
Author: User

    • Objective:

Lodash (i) just studied the various methods in the array, followed by the frequently used loop traversal problem

    • Process:

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
    • After statement:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.