Home > Web Front-end > JS Tutorial > JavaScript and jquey realize the merging operation of multiple arrays_javascript skills

JavaScript and jquey realize the merging operation of multiple arrays_javascript skills

WBOY
Release: 2016-05-16 16:36:52
Original
1152 people have browsed it

1. Native JavaScript implementation

var array1 = ["a", "b"];
var array2 = ["c", "d"];
Copy after login

I want to merge it into something like this:

<span class="keyword" style="font-weight:bold">var</span> <span class="keyword" style="font-weight:bold">array</span>= [<span class="string" style="color:rgb(221,17,68)">"a"</span>, <span class="string" style="color:rgb(221,17,68)">"b"</span>, <span class="string" style="color:rgb(221,17,68)">"c"</span>, <span class="string" style="color:rgb(221,17,68)">"d"</span>];
Copy after login

Can be used

arr1.concat(arr2);
Copy after login

2. Jquery implementation

$.merge(array1,array2);
console.log($.unique(array1));
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template