日期:2014-05-16  浏览次数:20340 次

js循环map,获取所有的key和value
//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 this.pageUrl){
   alert(key+" : "+this.pageUrl[key]);
}


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])
  }
}


双重Map循环
var msg = "";
for(var key in Pin) {
   for(var i in Pin[key]){
    msg+=i+": "+Pin[key][i]+"\n";
   }
}
alert(msg);