[Javascript] Iterate over Items with JavaScript ' s for-of Loop

Source: Internet
Author: User
Tags iterable

In this lesson we'll understand the for of loop in Javascript which is 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 s Pecified variable. This excludes plain objects as we'll see in the lesson.

Object.prototype.objCustom =function() {}; Array.prototype.arrCustom=function() {};let iterable= [3, 5, 7];iterable.foo= ' Hello '; for(Let Iinchiterable) {Console.log (i);//0, 1, 2, "foo", "Arrcustom", "Objcustom"} for(Let Iinchiterable) {  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 was because they are inherited. Not array and object ' s own prop.

[Javascript] Iterate over Items with JavaScript ' s for-of Loop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.