Home > Article > Web Front-end > How to use js to store key values
This time I will show you how to use the storage key value of js, and what are the precautions for using the storage key value of js. The following is a practical case, 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>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 hot replace webpack modules
Angular entry component and declarative component case comparison
The above is the detailed content of How to use js to store key values. For more information, please follow other related articles on the PHP Chinese website!