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
Release: 2016-10-10 11:56:15
Original
2294 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template