[Javascript] Iterate Over Items with JavaScript's for-of Loop
JavaScript for of with 39 Over loop
2023-09-14 09:00:51 时间
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.
相关文章
- JavaScript 编程易错点整理
- 细说JavaScript对象(4): for in 循环
- 【JavaScript 6连载】四、apply和call的用法
- Javascript对象的方法赋值
- 第一百三十九节,JavaScript,封装库--CSS选择器
- [Javascript] Broadcaster + Operator + Listener pattern -- 9. Create modify, filter, map operators
- [TypeScript] Use the JavaScript “in” operator for automatic type inference in TypeScript
- [Javascript] Iterate Over Items with JavaScript's for-of Loop
- [Javascript] String method: endsWith() && startsWith()
- [Javascript] Using map() function instead of for loop
- 理解Javascript_02_理解undefined和null [转]
- [Jest] Restore the Original Implementation of a Mocked JavaScript Function with jest.spyOn
- [Javascript] Create an Async Generator and Loop Through Generated Promises with "For Await Of" Loops
- [Javascript] Wait for the Fastest JavaScript Promise to Be Fulfilled with Promise.any()
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part4
- [Algorithm] Breadth First JavaScript Search Algorithm for Graphs
- [Javascript] Case insensitive sorting for string arrays
- [Javascript] Stop writing For loops. Start using underscore
- 关于Fiori应用sandbox JavaScript的两个疑问
- SAP Cloud for Customer里的HTML Mashup的JavaScript编程功能
- C4C的Rich text editor的JavaScript实现
- jQWidgets 15.0 for JavaScript Crack
- 【 华为OD机试 2023】 最快到达医院的方法(C++ Java JavaScript Python)
- 每天一个JavaScript实例-从一个div元素删除一个段落
- python web py入门(36)- javascript的if条件语句
- 创建 JavaScript 对象
- 前端学习路线-学习web前端的最 佳路线:必备javascript书籍【含红宝书和绿皮书、黄宝书等】