在JavaScript代码中让contact函数合并两个数组
下面的代码演示了JS中如何将两个数组连接成一个数组
<p id="demo">Click the button to join three arrays.</p> <button>Try it</button> function myFunction() { var hege = ["Cecilie", "Lone"]; var stale = ["Emil", "Tobias", "Linus"]; var kai = ["Robin"]; var children = hege.concat(stale,kai); var x=document.getElementById("demo"); x.innerHTML=children; }
连接后的数组为:Cecilie,Lone,Emil,Tobias,Linus,Robin