zoukankan      html  css  js  c++  java
  • javascript unshift()和shift()

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <script type="text/javascript">
    console.log('unshift()和shift()方法的行为非常类似于push()和pop(),不一样的是前者在数组的头部而非尾部进行元素的插入和删除操作。');
    console.log('unshift() 在数组的头部添加一个或多个元素,并将已存在的元素移动到更高索引的位置来获得足够的空间,最后返回数组新的长度。');
    console.log('shift()删除数组的第一个元素并将其返回,然后把所有随后的元素下移一个位置来填补数组头部的空缺。');
    
    
    var a=[];
    var ret=a.unshift(1);
    console.log('01. a.unshift(1)   a='+a+' : ret='+ret);
    ret =a.unshift(22);
    console.log('02. a.unshift(22)  a='+a+' : ret='+ret);
    a.shift();
    console.log('03. a.shift()  a='+a+' : ret='+ret);
    a.unshift(3,[4,5]);
    console.log('04. a.unshift(3,[4,5])  a='+a+' : ret='+ret);
    a.shift();
    console.log('05. a.shift()  a='+a+' : ret='+ret);
    a.shift();
    console.log('06. a.shift()  a='+a+' : ret='+ret);
    a.shift();
    console.log('07. a.shift()  a='+a+' : ret='+ret);
    
    </script>
    </body>
    </html>
  • 相关阅读:
    CF919F A Game With Numbers
    CF1005F Berland and the Shortest Paths
    CF915F Imbalance Value of a Tree
    CF1027F Session in BSU
    CF1029E Tree with Small Distances
    CF1037E Trips
    CF508E Arthur and Brackets
    CF1042F Leaf Sets
    [HNOI2012]永无乡
    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理
  • 原文地址:https://www.cnblogs.com/qq-757617012/p/4611525.html
Copyright © 2011-2022 走看看