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>
本文转载自:http://www.cnblogs.com/niuniudashijie/p/6080163.html