1.数组转json格式:
const a = ['1', '200', '11', '31', '151', '9', '15', '99', '48', '78', '1101', '60', '80', '56', '12', '21', '31', '32', '34', '56', '78', '99', '48', '78', '1101', '60', '80', '56', '1101', '200', '11', '31', '151', '9', '15'];
const c = {"普通":{},"白银":{},"黄金":{},"铂金":{},"砖石":{}};
const keys = Object.keys(c);
for (let i = 0; i < keys.length; i++) {
c[keys[i]].minScore = a[(i * 7) + 0];
c[keys[i]].maxScore = a[(i * 7) + 1];
c[keys[i]].firstCommission = a[(i * 7) + 2];
c[keys[i]].secondCommission = a[(i * 7) + 3];
c[keys[i]].threeCommission = a[(i * 7) + 4];
c[keys[i]].fourthCommission = a[(i * 7) + 5];
c[keys[i]].fifthCommission = a[(i * 7) + 6];
}
console.log(c);//{"普通":{max:'asd'},'白银':{max:'asfd'}}
2.json转数组格式:
data2.forEach((item, index)=>{
if(index % 5 === 0){
obj = {
title: item.title,
odds: []
};
brr.push(obj);
} else{
obj.odds.push(item.odds)
}
})
brr.push()
console.log(brr)
打印:
odds:{
0: "1.99"
1: "1.99"
2: "1.99"
3: "1.99"
}
title: "第一球"