Get the App
SLTechnology News&Howtos  ›  Development  › 

Description and usage of for...of Loop in javascript

Shulou Source: shulou.com Published: 2022-06-03 17:30:58 11月13日 Update

This article introduces the relevant knowledge of "the explanation and use of the for...of cycle in javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. ES6 adds a for..of loop for iterating objects, which requires that objects must be iterated.

The object must meet the iterable protocol.

2. Available ranges include arrays, Set and Map structures, array objects, Generator objects, and strings.

Example

Const arr = ['red',' green', 'blue']; for (let v of arr) {console.log (v); / / red green blue} const obj = {}; obj [Symbol.iterator] = arr [Symbol.iterator] .bind (arr); for (let v of obj) {console.log (v); / / red green blue} "instructions and usage of for...of cycle in javascript" ends here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Objects loops iterations methods methods content arrays more knowledge practicality learning next dilemmas characters strings examples reality situations articles cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft Docker Shulou Information Apple