Home  >  Article  >  Web Front-end  >  Introduction to storage key-value pairs and precautions based on js

Introduction to storage key-value pairs and precautions based on js

亚连
亚连Original
2018-05-28 10:34:471501browse

Now I will introduce to you the key-value pairs stored in js and the precautions. I hope to be helpful.

The front end sometimes needs to store key-value pairs. The main point is that the key must be a string. It is important to note again that the key needs to be a string.

Key contents

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title> 
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
var map={
 key1:&#39;abc&#39;,
 key2:&#39;def&#39;
};
$(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>

The above is what I compiled for you. I hope it will be helpful to you in the future.

Related articles:

Introduction to the Builder pattern in Java design

In-depth analysis of the different mechanisms of computed and methods in Vue.js

A brief discussion on Webpack persistent caching practice

The above is the detailed content of Introduction to storage key-value pairs and precautions based on js. For more information, please follow other related articles on the PHP Chinese website!

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