Home >Web Front-end >JS Tutorial >Analysis of the value method when the json key is a number_javascript skills

Analysis of the value method when the json key is a number_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:15:001487browse

How to get the value when the key of json is a number, such as:
var aa={'111':'aaaaa'};
alert(sss.111);
This won't work, alert won't play anything.

The key of json must be an object to retrieve something, such as:
var aa={'s111s':'aaaaa'};
var idd="s111s";
alert(sss.idd);


Answer:

For numeric key names or abnormal variable characters (such as spaces), the aa[x] method must be used.
var aa={'111':'aaaaa'};
alert(sss["111"]);

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