Home  >  Article  >  Web Front-end  >  Use json method to create a map_javascript technique in js

Use json method to create a map_javascript technique in js

WBOY
WBOYOriginal
2016-05-16 16:50:281547browse

The way to create a map (actually the practical way is the json implementation)

Copy code The code is as follows:

var a = {};
a["key1"] = "value1";
a["key2"] = "value2";

Since it is a map, there is retrieval To check whether a key exists, write
Copy code The code is as follows:

if ( "key1" in a) {
// something
} else {
// something else
}

A simple sentence to declare the key and value in the map Way:
Copy code The code is as follows:

var a = {'key1': ' value1', 'key2': 'value2'}
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