Home > Web Front-end > JS Tutorial > Detailed explanation of the use of storing key-value pairs in js

Detailed explanation of the use of storing key-value pairs in js

php中世界最好的语言
Release: 2018-05-11 10:35:59
Original
3864 people have browsed it

This time I will bring you a detailed explanation of the use of stored key-value pairs in js. What are the precautions for using stored key-value pairs in js? Here are practical cases, let's take a look.

Key content

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
var map={
 key1:'abc',
 key2:'def'
};
$(document).ready(function(){
 $("button").click(function(){
  map.key3=333;//js 里的键必须为字符串
  for(var key in map){//可以迭代键
   alert(map[key])//依据键取值
  }
  alert("add value:"+map.key3);
 });
});
</script>
</head>
<body>
 <button>click</button>
</body>
</html>
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting content, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to implement and use p5.js mouse interaction

Use vue to highlight the a tag when clicked (With code)

The above is the detailed content of Detailed explanation of the use of storing key-value pairs in js. For more information, please follow other related articles on the PHP Chinese website!

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