日期:2014-05-16 浏览次数:20566 次
var ar = [0,0,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,'3..............................0',0,0,0,0,24]; ar = ar.join(',').replace(/0/g, '').split(','); alert(ar);
------解决方案--------------------
var str1 = "0,0,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,3..............................0,0,0,0,0,24" ;
var str2 = str1.replace(/0/g,'');
alert(str2);
------解决方案--------------------
楼上两个有错,出现10 100 01这种就不行
var ar = [0,0,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,'3..............................0',0,0,0,0,24]; for(var i=ar.length-1;i>=0;i--)ar[i]=ar[i]||'';
------解决方案--------------------
var a="0,0,0,0,0,1,0,0,0,0,0,2,0,0,0,0,0,3..............................0,0,0,0,0,24";
var reg=/0,/g;
a=a.replace(reg,",");
alert(a);
先把数组join成逗号分隔的字符串,然后试试