![](/img/trans.png)
[英](Javascript) Is there a way to define more than one property to a variable?
[英]access object property by variable with more than one “nodes” in javascript
想象一下這個對象:
var obj = {
one: {
two:{
three: "whatever"
}
}
}
如果我想訪問“任何內容”,則只需執行以下操作:
console.log( obj.one.two.three ) --> "whatever"
而且我什至可以使用像這樣的變量:
var one = "one"
console.log( obj[one].two.three ) --> "whatever"
但是為什么不起作用呢?
var onetwo = "one.two"
console.log( obj[onetwo].three ) --> undefined
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.