我有一个像这样的Javascript对象:
const childDict = {
address: {
zip: "GGHG654",
city: "Morocco",
number: 40
}
}
我想在这样的循环中动态地将它添加到另一个父字典中:
let parentDict = {}
for(let i = 0 ; i < 3; i++){
parentDict["place" + i] = childDict
}
所以最后我得到了一个像这样的字典:
{
place0: {
address: {
zip: "GGHG654",
city: "Morocco",
number: 40
}
},
place1: {
address: {
zip: "GGHG654",
city: "Morocco",
number: 40
}
}
}
然而,for循环给了我一个编译错误:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
慕工程0101907
九州编程
Smart猫小萌
慕桂英546537
随时随地看视频慕课网APP
相关分类