这是在节点外壳中完成的:
> results = []
[]
> num = 5
5
> results[num] = []
[]
> results
[ , , , , , [] ]
>
即使我尝试对数字进行字符串化:
> results = []
[]
> num = 5
5
> results[num.toString()] = []
[]
> results
[ , , , , , [] ]
> results['5'] = []
[]
> results
[ , , , , , [] ]
>
似乎javascript将字符串解释为对象定义中的数字?
我希望结果如下所示:
results = [ { '5' : [
{ key : value },
{ key2 : value }
]
}
]