This time I will bring you a detailed explanation of the steps to obtain key and value with js loop map. What are the precautions for js loop map to obtain key and value? The following is a practical case, let's take a look.
The following method 1 and method 2 have been tested and run by the editor of Script House
Method 1: json format definition
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <script> var dxy={ //Page地址 pageUrl : { menu : "loadPage.htm?url=/collect/menu.page", // 进入菜单页面 guangfaPage : "loadPage.htm?url=/collect/menu.page", // 进入广发信息收集页面 pinganPage : "loadPage.htm?url=/collect/menu.page", // 进入平安信息收集页面 nuonuoPage : "loadPage.htm?url=/collect/menu.page", // 进入诺诺信息收集页面 youbangPage : "loadPage.htm?url=/collect/menu.page", // 进入友邦信息收集页面 inputMobileNo : "loadPage.htm?url=/collect/inputMobileNo.page", // 进入输入手机号页面 readIdCard : "loadPage.htm?url=/collect/readIdCard.page", // 进入读取身份证页面 member : "loadPage.htm?url=/collect/member.page", // 进入输入会员卡号页面 bankCard : "loadPage.htm?url=/collect/bankCard.page", // 进入插入银行卡页面 url : "loadPage.htm?url=/collect/url.page" // 进入跳转url页面 } } for(var key in dxy.pageUrl){ alert(key+" : "+dxy.pageUrl[key]); } </script> </body> </html>
Code 2,
var obj = { "a": 1, "b": 2, "c": 3 }; for (var prop in obj) { if (obj.hasOwnProperty(prop)) { // or if (Object.prototype.hasOwnProperty.call(obj,prop)) for safety... alert("prop: " + prop + " value: " + obj[prop]) } }
The following are the supplements of other netizens. You can refer to them
javascriptLoopTraverse the arrayOutput key value
javascript loops through the array to output key value
Using the $.each method will definitely not work, so use the following method
markers = []; markers[2]=3; markers[3]=7; for(var key in markers){ console.log( key ) console.log( markers[key] ) }
I believe you have mastered the method after reading the case in this article. For more exciting things, please pay attention to php Other related articles on the Chinese website!
Recommended reading:
How to deal with async/await wasted performance problem
jQuery implementation of fuzzy query practical case analysis
The above is the detailed content of Detailed explanation of the steps to obtain key and value in js loop map. For more information, please follow other related articles on the PHP Chinese website!