萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> JavaScript使用concat連接數組的方法

JavaScript使用concat連接數組的方法

 下面的代碼演示了JS中如何通過concat函數鏈接多個數組

1 2 3 4 5 6 7 8 9 10 11 12 <!DOCTYPE html> <html> <body> <script> var parents = ["Jani", "Tove"]; var brothers = ["Stale", "Kai Jim", "Borge"]; var children = ["Cecilie", "Lone"]; var family = parents.concat(brothers, children); document.write(family); </script> </body> </html>

上面的代碼運行結果如下:

Jani,Tove,Stale,Kai Jim,Borge,Cecilie,Lone

copyright © 萬盛學電腦網 all rights reserved