日期:2014-05-16  浏览次数:20555 次

求一个数组的表达方式,有规律
需要的数组如下:
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 str=这个数组

然后把0用空值替换,变成,,,,,1,,,,,,2,,,,,,3..............................,,,,,24



------解决方案--------------------
JScript code
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这种就不行
JScript code

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成逗号分隔的字符串,然后试试