Summary of front-end learning notes (merge method)

Source: Internet
Author: User

Study Notes

Merge method of jquery

Not to mention, first

When using jquery, the smart prompt is as follows: Merge the first and second arrays. The result is the union of first + (the result after second deduplication ).

Next, perform the test:

1 $ (function () {2 var arr1 = ['apple', 'Orange ', 1, 'cherry', 'Orange']; 3 var arr2 = ['chen ', 343, true, 'cherry', 1]; 4 var result = $. merge (arr1, arr2); 5 console. log (result); // output: ["apple", "orange", 1, "Cherry", "orange", "Chen", 343, true, "Cherry ", 1] 6 });

It is strange that our ideal result should be output: ["apple", "orange", 1, "Cherry", "orange", "Chen", 343, true], if jquery is such a simple merge without deduplication, it would be better to use the native Concat method.

1 var arr1 = ['apple', 'Orange ', 1, 'cherry', 'Orange']; 2 var arr2 = ['chen', 343, true, 'cherry', 1]; 3 console. log (arr1.concat (arr2); // output: ["apple", "orange", 1, "Cherry", "orange", "Chen", 343, true, "Cherry", 1]

Finally, let's take a look at jquery's implementation of merge, as shown in:

It turns out that only merge is implemented, and repetition is not removed. I am messy. You didn't duplicate it. What is the whole merge? Is it better to use native Concat? I am a front-end cainiao, and above is the merge I know. I understand it incorrectly. Please point it out. Thank you!

Although this article is very watery, but: Do not remove the home page, garden administrator uncle, see the water written by others, if he has a good learning attitude, then not to remove the home page is also a kind of kind, giggle!

Summary of front-end learning notes (merge method)

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.