zoukankan      html  css  js  c++  java
  • JS-Array 对象——copyWithin使用方法

    Javascript 对象有

    1. Array对象
    2. Boolean对象
    3. Date对象
    4. Math对象
    5. Number对象
    6. String对象
    7. RegExp对象

    Array对象用于在变量中存储多个值。

      Array对象属性:

      copyWithin()   从数组的指定位置拷贝元素到数组的另一个指定位置中。

      用法:array.copyWithin(traget,start,end)

      Exp:

      

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="utf-8">
     5 <title>copyWithin()的用法</title>
     6 </head>
     7 <body>
     8 
     9 <p>点击按钮复制数组的前面两个元素到第三和第四个位置上。</p>
    10 
    11 <button onclick="myFunction()">点我</button>
    12 
    13 <p id="demo"></p>
    14 
    15 <p><strong>注意:</strong> IE 11 及更早版本不支持 copyWithin() 方法。</p>
    16     
    17 <script>
    18 var fruits = ["apple","pear","bannar","orange","watermelon","a"];
    19     document.getElementById("demo").innerHTML=fruits;
    20     function myFunction(){
    21         document.getElementById("demo").innerHTML = fruits.copyWithin(3,2,3);
    22     }
    23 </script>
    24 
    25 </body>
    26 </html>


     

  • 相关阅读:
    MVC模式的学生信息增删改查
    常用排序算法
    2803 爱丽丝·玛格特罗依德
    3118 高精度练习之除法
    中秋练习题
    poj2011
    P1558 色板游戏
    P1830 轰炸III
    P1656 炸铁路
    1067 机器翻译
  • 原文地址:https://www.cnblogs.com/johnhery/p/9800697.html
Copyright © 2011-2022 走看看