我有以下数组
var a = ["Banana/hgd/kjjkds", "Orange/kldj/kdl",
"Apple/jlds/ldks", "Mango/dsfj/dskj"]
现在我想重新创建它并制作输出
{
"a1" : "Banana",
"a2" : "hgd",
"a3" : "kjjkds"
}
{
"a1" : "Orange",
"a2" : "kldj",
"a3" : "kdl"
}
{
"a1" : "Apple",
"a2" : "jlds",
"a3" : "ldks"
}
{
"a1" : "Mango",
"a2" : "dsfj",
"a3" : "dskj"
}
我尝试了以下方法,但没有任何成功:
var b = [];
for (var i = 0; i< a.length; i++) {
b['a1'] = a[i].split("/")[0];
b['a2'] = a[i].split("/")[1];
b['a3'] = a[i].split("/")[2];
console.log(b);
b.push(b);
}
console
打印所有创建的数组,但仅array b
显示最后一个。我怎样才能让它工作?请帮忙。