简单教程
提交运行
代码编辑器:
<p>点击按钮复制数组的前面两个元素到第三和第四个位置上</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <p><strong>注意:</strong> IE 11 及更早版本不支持 copyWithin() 方法</p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi", "Papaya"]; document.getElementById("demo").innerHTML = fruits; function myFunction() { document.getElementById("demo").innerHTML = fruits.copyWithin(2,0,2); } </script>
运行结果: