2 回答

TA貢獻1856條經(jīng)驗 獲得超5個贊
您不需要拆分任何東西,您的數(shù)據(jù)已經(jīng)在數(shù)組的單獨條目中,位于series[index].data[0](數(shù)字)和series[index].data[1](字符串)處。所以你可以訪問循環(huán)中的那些,例如:
// (`i` is already declared in the OP's code)
for (i = 0; i < series.length; ++i) {
var num = series[i].data[0];
var str = series[i].data[1];
console.log(num, str);
}
現(xiàn)場示例:
var data = [
[,,,"Vinil s/ pó",,,,10000],
[,,,"Another value",,,,20000],
];
var series = [],
len = data.length,
i = 0;
for(i;i<len;i++){
series.push({
name: 'Janeiro',
data:[data[i][7], data[i][3]]
});
}
// Using each entry:
for (i = 0; i < series.length; ++i) {
var num = series[i].data[0];
var str = series[i].data[1];
console.log(num, str);
}
或者使用 ES2015+ 語言特性(for-of、解構(gòu)和const):
// Using each entry
for (const {data: [num, str]} of series) {
console.log(num, str);
}
現(xiàn)場示例:
var data = [
[,,,"Vinil s/ pó",,,,10000],
[,,,"Another value",,,,20000],
];
var series = [],
len = data.length,
i = 0;
for(i;i<len;i++){
series.push({
name: 'Janeiro',
data:[data[i][7], data[i][3]]
});
}
// Using each entry
for (const {data: [num, str]} of series) {
console.log(num, str);
}

TA貢獻1712條經(jīng)驗 獲得超3個贊
Series 似乎是一個對象數(shù)組,因為 split 是一個 String 方法,您不能在數(shù)組或?qū)ο笊鲜褂盟?/p>
在每個對象中,您都有指向數(shù)組的關(guān)鍵數(shù)據(jù),因此您不必按照您嘗試的方式拆分它。
只需訪問 series[index].data[innerArrIndex]
添加回答
舉報