【发布时间】:2021-03-24 15:17:44
【问题描述】:
我正在尝试访问对象的键。 但这行不通。有谁能帮帮我吗?
所以我有一个对象和一个指向我必须在对象内部访问的值的字符串。而且这个值下降了两个级别。
const obj = { name: 'yash', { hobbies: { sports: ['football', 'tennis']} } };
// this is an example object, I have a string
const item = 'hobbies.sports';
// now I want to access the object with this item
obj[item] // but this isn't working.
【问题讨论】:
-
@NicoHaase 不是真的。
-
“不是真的”是什么意思?请编辑您的问题以包含更多详细信息
标签: javascript object data-structures javascript-objects