时间:2021-07-01 10:21:17 帮助过:2人阅读
1、原生的JavaScript实现
var array1 = ["a", "b"]; var array2 = ["c", "d"];
我要合并后变成下面这样:
<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>];
可以使用
arr1.concat(arr2);
2、Jquery实现
$.merge(array1,array2); console.log($.unique(array1));