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

Use json method to create a map_javascript technique in js

WBOY
Release: 2016-05-16 16:50:28
Original
1551 people have browsed it

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'}
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