search
HomeWeb Front-endJS TutorialDetailed explanation of key and value steps obtained by js loop map

This time I will bring you a detailed explanation of the key and value steps obtained by js loop map. What are the precautions for the key and value obtained by js loop map. The following is a practical case, let's take a look.

Method 1: json format definition

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<meta>
<title>无标题文档</title>


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

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

Script House editor’s demonstration

li One row, four columns, alternate rows are displayed without using colors

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<meta>
<title>无标题文档</title>


<script>
var obj = { 
"http://www.2016idc.com/cdn.html" : "◆◆◆◆◆高防免备案CDN◆◆◆◆◆",
"http://www.zoneidc.com/" : "1G香港云49元/美国云49元/韩国云89元",
"http://click.aliyun.com/m/15321/" : "30余款阿里云产品免费6个月",
"http://www.kaivps.com/cloud.html": "◆好优云◆抗攻击◆无视CC◆免备◆稳定◆",
"http://www.laoyuming.com/new.html" : "【15000个备案老域名】每天更新400个",
"http://seo.whbtsj.com/" : "★百度快速上首页,无效果不收费★",
"http://www.osssnet.com/" : "◆50M香港/美国/日本服务器380免备案◆",
"http://www.cuwww.com" : "█香港服务器租用百兆带宽1300起█",
"http://www.guowaidiaocha.com/" : "★国外调查 月赚两万,一对一教学带你★",
"http://www.enkj.com/idc/" : "【亿恩】DELL品牌服务器,月付799元起",
"http://www.hkcn2.com/51.htm" : "**香港高防10m大带宽独服,低至999元**",
"https://www.zllyun.com/cloud.shtml" : "知了云,OpenStack云服务器◆5折优惠◆",
"http://www.8000idc.com" : "— — 香港云33元美国云39元快云21元 — —",
"https://www.50vm.com/" : "4核独服199/16核独服360|创梦网络",
"https://cloud.tencent.com/act/campus?fromSource=gwzcw.846004.846004.846004" : "腾讯云拼团福利 1核2G云服务器10元/月",
"http://www.zitian.cn/" : "中原地区核心数据中心,月付299元起",
"http://www.7yc.com/rent.html" : "██云彩网络██100G防服务器450元",
"http://www.dsx.top/" : "产品发布、创业开店、需求任务找大师兄",
"http://www.gwidc.com/rent/home/index.html" : "港湾网络-徐州百独16核16G 800/月~",
"http://www.ssf.cc/" : "免备vps20/百独799/双线350/45互联",
"http://www.ushk.net/server.html" : "██美港数据██高端香港服务器租用",
"http://vps.zzidc.com/tongji/jb51w.html" : "★☆云服务器5折,天天抽红包抵扣☆★",
"http://www.ku86.com/" : "百兆 12核24线程 16G内存 2T 999/月",
"http://www.xiaozhiyun.com/2016/" : "韩国\香港\美国站群服务器 巨牛网络",
"http://www.wsisp.net/sale/20170518/?indexjb" : "█▇▆5M独享云主机599/年▆▇█",
"http://www.qy.com.cn/" : "群英云服务器送10M带宽30G防御,49元起",
"http://www.tuidc.com/" : "服务器租用/托管-域名空间/认准腾佑科技",
"http://www.jjidc.com/" : "九九数据 — 工信部认可正规资质IDC接入商",
"https://www.95idc.com" : "95IDC█香港沙田CN2服务器 599/月",
"http://www.33ip.com/" : "枫信科技-江苏双线10M保证-399/元",
"https://youhui.jb51.net/" : "★★领取天猫淘宝最高2018元红包★★",
"http://www.pdidc.com/" : "浦东数据中心上海电信4星云主机30元/月起",
"http://www.139w.com/" : "鼎点网络百兆独享服务器仅需999元",
"http://www.360jq.com/hkshuang.htm" : "[香港双高防]无视CC★DDOS/堪比广东!",
"http://www.cyidc.cc/" : "畅游网络 百独服务器 包跑满 998元",
"http://www.wdw6.com/" : "服务器租用 199元起"
}; 
var jbstr="";
var i=0;
var color="blue";
for (var jbkey in obj) {
 if (obj.hasOwnProperty(jbkey)) {	 
 // or if (Object.prototype.hasOwnProperty.call(obj,prop)) for safety... 
 //alert(i);
  if(i % 4 == 0){
		if(color=="blue"){
			color="red";
		}else{
			color="blue";
		}
 	}
	jbstr+=&#39;<li><a href="&#39;+jbkey+&#39;" rel="external nofollow" target="_blank"><span style="color:&#39;+color+&#39;;">&#39;+obj[jbkey]+&#39;&#39;;
i++
 }
} 
document.write(jbstr);
</script>

Code 3, Double Map Loop

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

The following are the supplements from other netizens, you can refer to them

javascriptLoop Traverse the arrayOutput key value

javascript loops through the array to output key value
Using the $.each method will definitely not work, so the following method is used

markers = [];
    markers[2]=3;
    markers[3]=7;
    for(var key in markers){
      console.log( key )
      console.log( markers[key] )
    }

I believe I read this article You have mastered the case method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Angular4.x Detailed explanation of route redirection steps through route guards

jQuery implementation of fuzzy query steps Detailed explanation

The above is the detailed content of Detailed explanation of key and value steps obtained by js loop map. 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
es6数组怎么去掉重复并且重新排序es6数组怎么去掉重复并且重新排序May 05, 2022 pm 07:08 PM

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

JavaScript的Symbol类型、隐藏属性及全局注册表详解JavaScript的Symbol类型、隐藏属性及全局注册表详解Jun 02, 2022 am 11:50 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

原来利用纯CSS也能实现文字轮播与图片轮播!原来利用纯CSS也能实现文字轮播与图片轮播!Jun 10, 2022 pm 01:00 PM

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

JavaScript对象的构造函数和new操作符(实例详解)JavaScript对象的构造函数和new操作符(实例详解)May 10, 2022 pm 06:16 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

javascript怎么移除元素点击事件javascript怎么移除元素点击事件Apr 11, 2022 pm 04:51 PM

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

JavaScript面向对象详细解析之属性描述符JavaScript面向对象详细解析之属性描述符May 27, 2022 pm 05:29 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

foreach是es6里的吗foreach是es6里的吗May 05, 2022 pm 05:59 PM

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

整理总结JavaScript常见的BOM操作整理总结JavaScript常见的BOM操作Jun 01, 2022 am 11:43 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.