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));