Home >Backend Development >PHP Tutorial >javascript - If the field of the js object is dynamic, how to get the value of this dynamic field?
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?
?
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?
?
obj[key]. It is recommended to check out the basics