博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Javascript] Iterate Over Items with JavaScript's for-of Loop
阅读量:4313 次
发布时间:2019-06-06

本文共 844 字,大约阅读时间需要 2 分钟。

In this lesson we will understand the For Of loop in Javascript which was introduced in ES6. The for-of loop lets you iterate of an itterable object (array, string, set, or map) and returns each objects value in a specified variable. This excludes plain objects as we will see in the lesson.

 

Object.prototype.objCustom = function() {}; Array.prototype.arrCustom = function() {};let iterable = [3, 5, 7];iterable.foo = 'hello';for (let i in iterable) {  console.log(i); // 0, 1, 2, "foo", "arrCustom", "objCustom"}for (let i in iterable) {  if (iterable.hasOwnProperty(i)) {    console.log(i); // 0, 1, 2, "foo"  }}for (let i of iterable) {  console.log(i); // 3, 5, 7}

 

"accCustom" and "objCustom" are not logged in second loop is because they are inherited. Not array and object's own prop.

 

转载于:https://www.cnblogs.com/Answer1215/p/7518550.html

你可能感兴趣的文章
Neutron在给虚拟机分配网络时,底层是如何实现的?
查看>>
netfilter/iptables全攻略
查看>>
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>
在eclipse上用tomcat部署项目404解决方案
查看>>
web.xml 配置中classpath: 与classpath*:的区别
查看>>
suse如何修改ssh端口为2222?
查看>>
详细理解“>/dev/null 2>&1”
查看>>
suse如何创建定时任务?
查看>>
suse搭建ftp服务器方法
查看>>
centos虚拟机设置共享文件夹并通过我的电脑访问[增加smbd端口修改]
查看>>
文件拷贝(IFileOperation::CopyItem)
查看>>
MapReduce的 Speculative Execution机制
查看>>
大数据学习之路------借助HDP SANDBOX开始学习
查看>>
Hadoop基础学习:基于Hortonworks HDP
查看>>
为什么linux安装程序 都要放到/usr/local目录下
查看>>
Hive安装前扫盲之Derby和Metastore
查看>>
永久修改PATH环境变量的几种办法
查看>>
大数据学习之HDP SANDBOX开始学习
查看>>
Hive Beeline使用
查看>>