我必须动态地构建如下的对象结构。
"1":{
"A":"one.two.three"
},
"2":{
"B":"three.four.five"
},
"3":{
"c":"six.seven.eight"
},
etc....
Obj ={
A: "123",
B: "345",
C :"678"
}
预期输出应如下所示
"Parent" :{
"one":{
"two"{
"three" :"123" (from Obj A)
}
}
"three": {
"four":{
"five" :"345" (from Obj B)
}
}
etc...`
` }
所以我尝试了以下方法。但它不起作用。
Var temp = {}
temp["one"] ="1";
temp["two"] = temp; (and) temp["one"]
temp["three"] = temp; (and) temp["two"]
答案 0 :(得分:1)
你可以这样做:
var obj = {};
obj['temp'] = {};
obj['temp']['tree'] = {};
obj['temp']['tree']['two'] = {};
obj['temp']['tree']['two']['one'] = "1";
答案 1 :(得分:1)
&
输出为:" {" 3":{" 2":{" 1":1}}}"