jquery 拼接二维数组。。。。。

现有字符串 “120.0721750000|43.8780910000|111^120.052961|43.904955|测试数据” 生成为
[[120.0721750000,43.8780910000,111],[120.052961,43.904955,测试数据]]

下面是我写的,问题是两次值都是一样的,求指教,最好是有代码

var str = '120.0721750000|43.8780910000|111^120.052961|43.904955|测试数据';
var data_info_1 = [];
var data_info = [];
if (str.indexOf("^") > 0) {
for (var i = 0; i < str.split('^').length; i++) {
for (var j = 0; j < str.split('^')[i].split('|').length; j++) {
data_info_1[j]=(str.split('^')[i].split('|')[j]);
}
data_info.push(data_info_1);
}

    }

1个回答

var str = '120.0721750000|43.8780910000|111^120.052961|43.904955|测试数据';
var data_info = [];
if (str.indexOf("^") > 0) {
for (var i = 0; i < str.split('^').length; i++) {
var data_info_1 = [];
for (var j = 0; j < str.split('^')[i].split('|').length; j++) {
data_info_1[j]=(str.split('^')[i].split('|')[j]);
}
data_info[i] = data_info_1;
}
}
console.log(data_info);

![图片说明](https://img-ask.csdn.net/upload/201701/22/1485050786_682328.png)
u012536675
whueuwe 三克油
接近 4 年之前 回复
立即提问
相关内容推荐