Array of Lodash--javascript Library

Source: Internet
Author: User

these days and learned a lot of the original knowledge, in the weekend summed up some JavaScript library-lodash (Array) of the content, I hope in the future learning from time to review and update themselves.

The lodash-JavaScript Tool Library is very popular today, and here is a summary of some of the code I have for it :

1._.chunk refers to the element that merges an array by the specified length .

  _.chunk ([ ' A ' ' B ' Span style= "LINE-HEIGHT:21.6000003814697PX; Background-color:rgb (255, 255, 255); " >,  ' d '  

//→[[' A ', ' B '], [' C ', ' d ']

_.chunk ([' a ', ' B ', ' C ', ' d '], 3);

//→[[' A ', ' B ', ' C '], [' d ']]  

2._. Compact removes spurious values from array elements.

_.compact ([0, 1, false, 2, ', 3]);

//→[1, 2, 3]

The 3._.drop can output the element that deletes the specified position (the default value is 1), or 0 to return the original array .

_.drop ([1, 2, 3]);

//→[2, 3]

_.drop ([1, 2, 3], 2);

//→[3]

_.drop ([1, 2, 3], 5);

//→[]

_.drop ([1, 2, 3], 0);

//→[1, 2, 3] //This is the return of the original array.

4. _.difference deletes the same element as the second array in the first array element .

_.difference ([1, 2, 3], [5, 2, 10]);

//→[1, 3]

The 5._.intersetion is then output by locating the elements in several arrays .

_.intersection ([1, 2, 3], [5, 2, 1, 4], [2, 1]);

//→[1, 2]

6._.dropright I myself think this is the same as the basic usage of _.drop, except that this is removed from the right.

The 7._.findindex can output the opposite number of satisfied condition objects.

varUsers = [{' user ':' Barney ',' age ': 36,' Active ':false},  {' user ':' Fred ',' age ': 40,' Active ':true},                                                      {' user ':' Pebbles ',' age ': 1,' Active ':false}  ];

        function return

//→0

_.findindex (Users, { ' age ': 1});

//→2

8. (1.) _.first outputs the first element .

_.first ([1, 2, 3]);

//→1

_.first ([]);

//→undefined  

(2.)_.rest outputs the remainder of the element except the first one .

_.rest ([1, 2, 3]);

//→[2, 3]  

(3) _.last Output last element

_.last ([1, 2, 3]);

//→3

(4.)_.initial outputs the remaining elements in addition to the last element

_.initial ([1, 2, 3]);

//→[1, 2]

9. delete the original array 2, 3 after the output.

var array = [1, 2, 3, 1, 2, 3];

_.pull (Array, 2, 3);

Console.log (array);

//→[1, 1]

Ten._.without remove the elements from the array.

. Without ([1, 2, 1, 0, 3, 1, 4], 0, 1);

//→[2, 3, 4]











Array of Lodash--javascript Library

Related Article

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.