數(shù)組對象的concat方法可以把兩個(gè)或者多個(gè)數(shù)組連接起來,,組成一個(gè)新的數(shù)組。下面是一段使用了concat方法的JS代碼,。
JavaScript代碼
<script type = "text/javascript"> var arr = ["HTML","CSS","JavaScript","DOM"]; var arr2 = ["ASP.NET","PHP","J2EE","Python","Ruby"]; var arrNew = arr.concat(arr2); var arr3 = ["1","2","3","4"]; var arrNewNew = arr.concat(arr2,arr3); </script> 測試數(shù)組的concat方法上面的代碼執(zhí)行完,,arrNew將是arr和arr2兩個(gè)數(shù)組的組合,arrNew的length是兩個(gè)數(shù)組length之和,。 concat方法也可以接受多個(gè)參數(shù),。例如:var arrNewNew = arr.concat(arr2,arr3); 這個(gè)語句將arr與arr2與arr3一起連接成一個(gè)新的數(shù)組。 |
|