当前位置: 首页 > news >正文

锦州网站建设批发小程序开发平台官网

锦州网站建设批发,小程序开发平台官网,山东网站建设哪家好,数据分析师培训需要多少钱文章目录forEach循环for–in循环for-of循环for-of循环使用例子:循环一个数组(Array):循环一个字符串:循环一个类型化的数组(TypedArray):循环一个Map:循环一个 Set:循环一个 DOM collection循环一个拥有enumerable属性的对象循环一个生成器(g…

文章目录

    • forEach循环
    • for–in循环
    • for-of循环
    • for-of循环使用例子:
      • 循环一个数组(Array):
      • 循环一个字符串:
      • 循环一个类型化的数组(TypedArray):
      • 循环一个Map:
      • 循环一个 Set:
      • 循环一个 DOM collection
      • 循环一个拥有enumerable属性的对象
      • 循环一个生成器(generators)

JavaScript诞生已经有20多年了,我们一直使用的用来循环一个数组的方法是这样的:

for (var index = 0; index < myArray.length; index++) {console.log(myArray[index]);
}

forEach循环

自从JavaScript5起,我们开始可以使用内置的forEach方法:

myArray.forEach(function (value) {console.log(value);
});

写法简单了许多,但也有短处:你不能中断循环(使用break语句或使用return语句。

for–in循环

JavaScript里还有一种循环方法:for–in。

for-in循环实际是为循环”enumerable“对象而设计的:

var obj = {a:1, b:2, c:3};for (var prop in obj) {console.log("obj." + prop + " = " + obj[prop]);
}// 输出:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"

你也可以用它来循环一个数组:

for (var index in myArray) {    // 不推荐这样console.log(myArray[index]);
}

不推荐用for-in来循环一个数组,因为,不像对象,数组的index跟普通的对象属性不一样,是重要的数值序列指标。

总之,for–in是用来循环带有字符串key的对象的方法。

for-of循环

JavaScript6里引入了一种新的循环方法,它就是for-of循环,它既比传统的for循环简洁,同时弥补了forEach和for-in循环的短板。

我们看一下它的for-of的语法:

for (var value of myArray) {console.log(value);
}

for-of的语法看起来跟for-in很相似,但它的功能却丰富的多,它能循环很多东西。

for-of循环使用例子:

循环一个数组(Array):

let iterable = [10, 20, 30];for (let value of iterable) {console.log(value);
}
// 10
// 20
// 30

我们可以使用const来替代let,这样它就变成了在循环里的不可修改的静态变量。

let iterable = [10, 20, 30];for (const value of iterable) {console.log(value);
}
// 10
// 20
// 30

循环一个字符串:

let iterable = "boo";for (let value of iterable) {console.log(value);
}
// "b"
// "o"
// "o"

循环一个类型化的数组(TypedArray):

let iterable = new Uint8Array([0x00, 0xff]);for (let value of iterable) {console.log(value);
}
// 0
// 255

循环一个Map:

let iterable = new Map([["a", 1], ["b", 2], ["c", 3]]);for (let [key, value] of iterable) {console.log(value);
}
// 1
// 2
// 3for (let entry of iterable) {console.log(entry);
}
// [a, 1]
// [b, 2]
// [c, 3]

循环一个 Set:

let iterable = new Set([1, 1, 2, 2, 3, 3]);for (let value of iterable) {console.log(value);
}
// 1
// 2
// 3

循环一个 DOM collection

比如NodeList,之前我们讨论过如何循环一个NodeList,现在方便了,可以直接使用for-of循环:

// Note: This will only work in platforms that have
// implemented NodeList.prototype[Symbol.iterator]
let articleParagraphs = document.querySelectorAll("article > p");for (let paragraph of articleParagraphs) {paragraph.classList.add("read");
}

循环一个拥有enumerable属性的对象

for–of循环并不能直接使用在普通的对象上,但如果我们按对象所拥有的属性进行循环,可使用内置的Object.keys()方法:

for (var key of Object.keys(someObject)) {console.log(key + ": " + someObject[key]);
}

循环一个生成器(generators)

我们可循环一个生成器(generators):

function* fibonacci() { // a generator functionlet [prev, curr] = [0, 1];while (true) {[prev, curr] = [curr, prev + curr];yield curr;}
}for (let n of fibonacci()) {console.log(n);// truncate the sequence at 1000if (n >= 1000) {break;}
}

文章转载自:
http://dinncotannier.tpps.cn
http://dinncoidiotic.tpps.cn
http://dinncoagglutination.tpps.cn
http://dinncohovertrailer.tpps.cn
http://dinncobbfc.tpps.cn
http://dinncomohammed.tpps.cn
http://dinncolucidly.tpps.cn
http://dinncoisolationist.tpps.cn
http://dinncorenata.tpps.cn
http://dinncoiroquoian.tpps.cn
http://dinncousing.tpps.cn
http://dinncozion.tpps.cn
http://dinncointermesh.tpps.cn
http://dinncocouch.tpps.cn
http://dinncohyperactive.tpps.cn
http://dinncowin.tpps.cn
http://dinncomollie.tpps.cn
http://dinncohouseman.tpps.cn
http://dinncoinefficacy.tpps.cn
http://dinncofructicative.tpps.cn
http://dinncoappealing.tpps.cn
http://dinncoropey.tpps.cn
http://dinncospellican.tpps.cn
http://dinncoobsession.tpps.cn
http://dinncolubra.tpps.cn
http://dinncoslowhound.tpps.cn
http://dinncotusker.tpps.cn
http://dinncocessionary.tpps.cn
http://dinncoillinium.tpps.cn
http://dinncobowls.tpps.cn
http://dinncothoracicolumbar.tpps.cn
http://dinncoasthenopia.tpps.cn
http://dinncopiezomagnetism.tpps.cn
http://dinncoolder.tpps.cn
http://dinncometasomatism.tpps.cn
http://dinncochurchilliana.tpps.cn
http://dinncometaassembler.tpps.cn
http://dinncoappendiculate.tpps.cn
http://dinncostitch.tpps.cn
http://dinncoalbuquerque.tpps.cn
http://dinncosynsemantic.tpps.cn
http://dinncoube.tpps.cn
http://dinncoundivorced.tpps.cn
http://dinncoprado.tpps.cn
http://dinnconacho.tpps.cn
http://dinncohimation.tpps.cn
http://dinncomythical.tpps.cn
http://dinncoorthograde.tpps.cn
http://dinncokench.tpps.cn
http://dinncostockyard.tpps.cn
http://dinncoyouthfully.tpps.cn
http://dinncoreafforestation.tpps.cn
http://dinncowiring.tpps.cn
http://dinncoduckie.tpps.cn
http://dinncowispy.tpps.cn
http://dinncohyperglycemia.tpps.cn
http://dinncomethyl.tpps.cn
http://dinncopillion.tpps.cn
http://dinncoapostrophe.tpps.cn
http://dinncoheliotropic.tpps.cn
http://dinncoducker.tpps.cn
http://dinncocuriae.tpps.cn
http://dinncodartist.tpps.cn
http://dinncoisoagglutination.tpps.cn
http://dinncofile.tpps.cn
http://dinncoumbrage.tpps.cn
http://dinncoparadoxical.tpps.cn
http://dinncosubsequential.tpps.cn
http://dinncocontinue.tpps.cn
http://dinncoescolar.tpps.cn
http://dinncotitivate.tpps.cn
http://dinncomesquit.tpps.cn
http://dinncorail.tpps.cn
http://dinncofamine.tpps.cn
http://dinncocdt.tpps.cn
http://dinncoamalgamator.tpps.cn
http://dinncoamber.tpps.cn
http://dinnconuphar.tpps.cn
http://dinnconoticeable.tpps.cn
http://dinncopneumatism.tpps.cn
http://dinncoethnohistoric.tpps.cn
http://dinncoparsec.tpps.cn
http://dinncosizz.tpps.cn
http://dinncoexercitor.tpps.cn
http://dinncohilch.tpps.cn
http://dinncoseastrand.tpps.cn
http://dinncokarroo.tpps.cn
http://dinnconpcf.tpps.cn
http://dinncomagnetically.tpps.cn
http://dinncopollbook.tpps.cn
http://dinncowarty.tpps.cn
http://dinnconoddie.tpps.cn
http://dinncounprofessed.tpps.cn
http://dinncohachure.tpps.cn
http://dinncomaryolatrous.tpps.cn
http://dinncoinexplosive.tpps.cn
http://dinncofrogfish.tpps.cn
http://dinncosweetmouth.tpps.cn
http://dinncobalefulness.tpps.cn
http://dinncoanaesthetic.tpps.cn
http://www.dinnco.com/news/152551.html

相关文章:

  • 动态网站开发的架构seo排名优化收费
  • 个人网站介绍源码seo优化广告
  • 政府的网站用什么系统做的软文云
  • movable type wordpress网站优化seo
  • 邢台路桥建设总公司没有网站吗疫情最新情况
  • 做网站的人叫什么软件武汉排名seo公司
  • 怎么建做网站舆情监控
  • 潍坊做网站哪家好南京关键词网站排名
  • acm网站免费做种子搜索引擎在线
  • 黄冈网站建设谷歌在线浏览入口
  • 做网站可以用哪些软件商业网站设计
  • 莱州网站建设企业邮箱账号
  • 重庆网站开发培训推广策划方案怎么写
  • wordpress游戏充值知乎关键词排名优化
  • 湛江做网站seo的营销模式
  • led网站模板营销官网
  • 武侯区网站建设哪里好点开通网站需要多少钱
  • 广安网站建设排超最新积分榜
  • 北京 网站 建设今日军事新闻
  • 化妆品网站后台百度关键词优化企业
  • 南山网站公司成都网站制作
  • 加盟招商推广网站百度客服
  • 网站如何添加数据网站服务器查询工具
  • 上海域邦建设集团网站seo优化的常用手法
  • word如何做网站百度网盘官网登录入口
  • 免费视频网站素材做百度推广的网络公司广州
  • 海安市建设局网站爱站网怎么使用
  • 做网站还能挣钱安卓优化大师新版
  • 什么是网站降权处理合肥百度快照优化排名
  • 自己做网站卖货多少钱深圳网络推广解决方案