Home >Web Front-end >JS Tutorial >How to store key values ​​in js in the project

How to store key values ​​in js in the project

php中世界最好的语言
php中世界最好的语言Original
2018-06-12 11:50:491336browse

This time I will show you how to use js to store key values ​​in a project, and what are the precautions for using js to store key values ​​in a project. The following is a practical case, let's take a look.

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

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

Recommended reading:

Postman simulates sending token

##Watchers, components and routing control in Vue.js

The above is the detailed content of How to store key values ​​in js in the project. 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