求一个数组代码-----------在线等!!! 这样恐怕不行,你要在每一段之间加上特殊标记,然后split 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function parse(str) { var result = []; var arr = str.split("|"); for (var i = 0; i <= arr.length / 5; i++) { var person = []; person.push(arr[i * 5 + 1]); person.push(arr[i * 5 + 2]); person.push(arr[i * 5 + 3]); person.push(arr[i * 5 + 4]); person.push(arr[i * 5 + 5]); result.push(person); } return result; } 试试var strContact = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]", reg = /(\|[^|]+){4}\|\w+@\w+\.(?:com|cn|org|net)/gi, rs, person = [];rs = strContact.match(reg);if(rs){ for(var i=0,il=rs.length;i<il;i++){ person.push(rs[i].substring(1).split(/\|/)) }} function showResult() { var strContact = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]"; var strList = strContact.split("|"); var personInfo = ""; var arr = new Array(); var reg = /[,]$/; for (var i = 1, len = strList.length; i <= len; i++) { if (strList[i] != "") { personInfo += '"' + strList[i] + '",'; } if (i % 5 == 0) { var str = personInfo.replace(/[,]$/, ""); arr.push(str); personInfo = ""; } } /* 结果: "联系人ID1","张三","010-88888888","13666666666","[email protected]" "联系人ID2","李四","010-88888888","13666666666","[email protected]" "联系人ID3","王五","010-88888888","13666666666","[email protected]" */ return arr; } <script type="text/javascript">var s = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]" var t=s.split("|"); var c=(t.length-1)/5; var b=new Array() var d=new Array(); for(var i=1;i<t.length;i++){ d[i-1]=t[i]; } var q=0; for(var j=0;j<c;j++){ b[j]=new Array(); for(var i=0;i<((t.length-1)/c);i++){ b[j][i]=d[i+q*5]; } q++; } alert(b["0"]); alert(b["1"]); alert(b["2"]);</script> 每秒刷新一次 document.body.scrollHeight在IE8和FF中取得的值为什么不一样? 急!!希望大家帮忙,如何实现多个页面随意浮动广告???? 网址复制给好友 求Javascript调试工具,大家都用什么工具调试阿 请问scoutlin一个关于xsl和vml的问题,详细见内,别的高手也可以进来哦,谢谢 如何将ASP中VB数组的值附给JS数组? 如何让select下拉菜单默认显示规定的值 如何用js进行对类的封装 怎样删除滚动框的最后一行字符? JS中,如何把字符串转成DOCUMENT对象 chrome中window.onerror不能用,有代替的方法吗?
function parse(str) {
var result = [];
var arr = str.split("|");
for (var i = 0; i <= arr.length / 5; i++) {
var person = [];
person.push(arr[i * 5 + 1]);
person.push(arr[i * 5 + 2]);
person.push(arr[i * 5 + 3]);
person.push(arr[i * 5 + 4]);
person.push(arr[i * 5 + 5]); result.push(person);
} return result;
}
reg = /(\|[^|]+){4}\|\w+@\w+\.(?:com|cn|org|net)/gi,
rs,
person = [];
rs = strContact.match(reg);
if(rs){
for(var i=0,il=rs.length;i<il;i++){
person.push(rs[i].substring(1).split(/\|/))
}
}
function showResult() {
var strContact = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]";
var strList = strContact.split("|"); var personInfo = "";
var arr = new Array(); var reg = /[,]$/;
for (var i = 1, len = strList.length; i <= len; i++) {
if (strList[i] != "") {
personInfo += '"' + strList[i] + '",';
}
if (i % 5 == 0) {
var str = personInfo.replace(/[,]$/, "");
arr.push(str);
personInfo = "";
}
} /* 结果:
"联系人ID1","张三","010-88888888","13666666666","[email protected]"
"联系人ID2","李四","010-88888888","13666666666","[email protected]"
"联系人ID3","王五","010-88888888","13666666666","[email protected]"
*/
return arr;
}
<script type="text/javascript">
var s = "|联系人ID1|张三|010-88888888|13666666666|[email protected]|联系人ID2|李四|010-88888888|13666666666|[email protected]|联系人ID3|王五|010-88888888|13666666666|[email protected]"
var t=s.split("|");
var c=(t.length-1)/5;
var b=new Array()
var d=new Array();
for(var i=1;i<t.length;i++){
d[i-1]=t[i];
}
var q=0;
for(var j=0;j<c;j++){
b[j]=new Array();
for(var i=0;i<((t.length-1)/c);i++){
b[j][i]=d[i+q*5];
}
q++;
}
alert(b["0"]);
alert(b["1"]);
alert(b["2"]);
</script>