小程序或者js怎么把这个数据 组合成数组对象 20
varmycars=newArray()mycars[0]=1mycars[1]=2mycars[2]=3varshangpin=[];//把数组转换成json数组var...
var mycars = new Array()
mycars[0] = 1
mycars[1] = 2
mycars[2] = 3
var shangpin = []; //把数组转换成json数组
var d = []; //把数组转换成json数组
var json = new Object(); //等于 var json = {};
for (var i = 1; i <= mycars.length; i++) {
var cur = mycars[i - 1]
switch (cur) {
case 1:
json.name = '抗皱皎洁白00'
break;
case 2:
json.name = '抗皱黑色111'
break;
default:
json.name = '抗皱黑色22'
}
shangpin.push(json);
var res = JSON.stringify(shangpin[0]);
console.log(res);
// var ress = d.push(res)
// console.log(ress);
}
} 展开
mycars[0] = 1
mycars[1] = 2
mycars[2] = 3
var shangpin = []; //把数组转换成json数组
var d = []; //把数组转换成json数组
var json = new Object(); //等于 var json = {};
for (var i = 1; i <= mycars.length; i++) {
var cur = mycars[i - 1]
switch (cur) {
case 1:
json.name = '抗皱皎洁白00'
break;
case 2:
json.name = '抗皱黑色111'
break;
default:
json.name = '抗皱黑色22'
}
shangpin.push(json);
var res = JSON.stringify(shangpin[0]);
console.log(res);
// var ress = d.push(res)
// console.log(ress);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询