如何在 for 循环中设置自定义 JSON 对象名称。
var myArray = [];
for (var i = 0; i<= 8; i++){
var x = "name" + i;
myArray.push({x:[0,0,0]});
}
我要这个
myArray = [
{name0:[0,0,0]},
{name1:[0,0,0]},
{name2:[0,0,0]},
{name3:[0,0,0]},
{name4:[0,0,0]},
{name5:[0,0,0]},
{name6:[0,0,0]},
{name7:[0,0,0]},
{name8:[0,0,0]},
];
但它返回这个
myArray = [
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
{x:[0,0,0]},
];