JS中如何将一组字符或者数值转换成数组? 比如:001002003这一串字符,装换成a["001","002","003"]这种形式的,可以每三位是一个数组值,请问各位高手能实现么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var s = "001002003"var re = new RegExp(".{3}","g")var a = []while ((n=re.exec(s)) != null){ a[a.length] = n[0]}for(i in a) alert(a[i]) <script type="text/javascript">var test = "0010020034";var arrTest = [];var item = "";for (var index = 0; index < test.length; index++) { item = item + test.charAt(index); if (((index + 1) % 3 == 0 && item.length > 0) || index == test.length - 1) { arrTest.push(item); item = ""; }}for (var index = 0; index < arrTest.length; index++) { alert(arrTest[index]);}</script> var s = "001002003"var reg=/\d{3}/g;alert(s.match(reg)) 完善下,不足3个数的显示var s = "00100200343"var reg=/\d{3}|\d{2}|\d{1}/g;alert(s.match(reg)) <script>var s="00100200343";alert(s.match(/\d{3}|\d+$/g));</script> js解析类json字符串 表单字符匹配的问题 请问这样的函数怎么绑定?? 复杂的登录 Ext.toolBar 与 button 区别 js cookies 关于访客来路记录的问题 关于下拉列表排序的问题? 爷爷二七,散分散代码表示悼念。 怎样判断一个变量是数组!?? 复选框的问题 javascript如何调用本地txt中的数据 getElementById失效,变成byName了.疑惑中,高手进---
var s = "001002003"
var re = new RegExp(".{3}","g")
var a = []
while ((n=re.exec(s)) != null){
a[a.length] = n[0]
}
for(i in a) alert(a[i])
var test = "0010020034";
var arrTest = [];
var item = "";
for (var index = 0; index < test.length; index++) {
item = item + test.charAt(index);
if (((index + 1) % 3 == 0 && item.length > 0) || index == test.length - 1) {
arrTest.push(item);
item = "";
}
}for (var index = 0; index < arrTest.length; index++) {
alert(arrTest[index]);
}</script>
var reg=/\d{3}/g;
alert(s.match(reg))
var s = "00100200343"
var reg=/\d{3}|\d{2}|\d{1}/g;
alert(s.match(reg))
var s="00100200343";
alert(s.match(/\d{3}|\d+$/g));
</script>