I'm almost finished with extracting the value from the JSON string. When I do console.log(rs.query.pages[19].revisions[0])
I get
Object {key1: "value1", key2: "value2", *: "value3"}
But, all I need is to extract value3
only. How to get that value by the key *?
When I try (and of course it won't work) console.log(rs.query.pages[19].revisions[0].*)
I get
Uncaught SyntaxError: Unexpected token *
What's the correct way to get value3
?
You can put "*" as a string in square brackets:
console.log(rs.query.pages[19].revisions[0]["*"])
That'll always work, regardless of how "messy" the property name is. When property names look like valid JavaScript identifiers, you can use the .
notation.
console.log(rs.query.pages[19].revisions[0]["*"])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.