Home > Article > Web Front-end > Introduction to storage key-value pairs and precautions based on js_javascript skills
The following editor will introduce to you the key-value pairs stored in js and the precautions. I hope to be helpful. Let’s follow the editor and 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 state 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:'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>
Related recommendations:
html5 Guide-5. Use web storage to store key-value pairs of data_html5 tutorial tips
The above is the detailed content of Introduction to storage key-value pairs and precautions based on js_javascript skills. For more information, please follow other related articles on the PHP Chinese website!