JavaScript及jquey实现多个数组的合并操作_javascript技巧

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

1、原生的JavaScript实现

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

我要合并后变成下面这样:

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

可以使用

arr1.concat(arr2);
Copy after login

2、Jquery实现

$.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