我有一個像這樣的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 '{}'.
javascript如何動態地將子字典附加到父字典
慕工程0101907
2022-05-22 18:01:25