【发布时间】:2019-01-14 20:38:16
【问题描述】:
这是我的例子。我在 Javascript 中有一个动态更改的对象。
在这种情况下,我想要“内部”属性的值,我知道该值在a[something][anotherthing][inside] 的位置。因为我将位置保存在数组["a","somethig", "anotherthing"] 中。我的问题是如何使用数组中的键移动到该位置?已经尝试连接元素,最终结果类似于myObject[a][somthing][anotherthing],但问题是它返回“未定义”,因为它是一个字符串。是否有机会将其转换为对象或以某种方式在对象中获得该位置?
var myarray = ['a', 'something', 'anotherthing'];
myObject = {
a: {
something: {
anotherthing: {
inside: 10
}
}
},
b: {
insideb: {}
}
}
【问题讨论】:
标签: javascript arrays for-loop javascript-objects