Home >Backend Development >PHP Tutorial >javascript - If the field of the js object is dynamic, how to get the value of this dynamic field?

javascript - If the field of the js object is dynamic, how to get the value of this dynamic field?

WBOY
WBOYOriginal
2016-10-10 11:56:152314browse

var obj={
"key1":"v1",
"key2":"v2"
}

If the value of key2 is taken, it is obj.key2

But if you want to retrieve it dynamically, such as var key="key2"
obj.key?

How to write

?

Reply content:

var obj={
"key1":"v1",
"key2":"v2"
}

If the value of key2 is taken, it is obj.key2

But if you want to retrieve it dynamically, such as var key="key2"
obj.key?

How to write

?

obj[key]. It is recommended to check out the basics

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn