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)