码迷,mamicode.com
首页 > 编程语言 > 详细

数组Demo

时间:2018-10-16 21:57:44      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:nbsp   数组   ons   col   console   去掉   length   number   存储   

要求将数组中的0项去掉,将不为0的值存入一个新的数组,生成新的数组

var newArray = []; // 空数组
for (var i = 0; i < numbers.length; i++) {
   if (numbers[i] !== 0) {
       //numbers[i];
       //找到的非0元素,存储到新的数组中
    newArray[newArray.length] = numbers[i];
    }
 }
 console.log(newArray);

 

数组Demo

标签:nbsp   数组   ons   col   console   去掉   length   number   存储   

原文地址:https://www.cnblogs.com/webmc/p/9800622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!