For example, the object property name has a number, I want to add a property to the for traversal object, the property name must have a number.
The printed results are as follows:
[{
room[1]: 1
},
{
room[2]: 2
},
{
room[3]: 3
},
{
room[4]: 4
},
{
room[5]: 5
},
{
room[6]: 6
}
]
var = arr[]
for (let index = 0; index < 10; index++) {
arr.push({
`room[${index}]`: index,
})
}
console.log(arr)
Is missing something called computed-property names:
Assuming there is a typo in the declaration of the variable arr
var arr = [];
for (let index = 0; index < 10; index++) {
arr.push({
[`room[${index}]`]/*Computed-property names*/: index,
});
}
console.log(arr)
.as-console-wrapper { min-height: 100%; }