zoukankan      html  css  js  c++  java
  • JS,数组小练习

    var arr = [4, 0, 7, 9, 0, 0, 2, 6, 0, 3, 1, 0];
    要求将数组中的0项去掉,将不为0的值存入一个新的数组,生成新的数组

    <!doctype html>

    <html lang="en">

     

    <head>

    <meta charset="UTF-8" />

    <title></title>

    </head>

     

    <body>

     

    </body>

    <script type="text/javascript">

    var arr = [4, 0, 7, 9, 0, 0, 2, 6, 0, 3, 1, 0];

    var pp = [];
    for(var i = 0; i < arr.length; i++) {
    if(arr[i] != 0) {
    pp.push(arr[i]);

    }

    }
    document.write(pp);

    </script>

     

    </html>

  • 相关阅读:
    winfrom 获取当前系统时间
    netcore3.1API+efcore快速搭建
    php
    php
    php
    php-array的相关函数使用
    php-正则表达式
    vim的复制与粘贴
    vim的多窗口和文件切换操作
    laravel教程中出现500问题
  • 原文地址:https://www.cnblogs.com/niuniudashijie/p/6080163.html
Copyright © 2011-2022 走看看