JavaScript Iterables | 您所在的位置:网站首页 › 青铜峡黄河楼花了多少钱 › JavaScript Iterables |
JavaScript Iterables
❮ Previous
Next ❯
Iterables are iterable objects (like Arrays). Iterables can be accessed with simple and efficient code. Iterables can be iterated over with for..of loops The For Of LoopThe JavaScript for..of statement loops through the elements of an iterable object. Syntax for (variable of iterable) { // code block to be executed } IteratingIterating is easy to understand. It simply means looping over a sequence of elements. Here are some easy examples: Iterating over a String Iterating over an Array Iterating Over a StringYou can use a for..of loop to iterate over the elements of a string: Example const name = "W3Schools";for (const x of name) { // code block to be executed } Try it Yourself » Iterating Over an ArrayYou can use a for..of loop to iterate over the elements of an Array: Example const letters = ["a","b","c"];for (const x of letters) { // code block to be executed } Try it Yourself »You can learn more details about Iterables in the chapter JS Object Iterables. Iterating Over a SetYou can use a for..of loop to iterate over the elements of a Set: Example const letters = new Set(["a","b","c"]);for (const x of letters) { // code block to be executed } Try it Yourself »Sets and Maps are covered in the next chapters. Iterating Over a MapYou can use a for..of loop to iterate over the elements of a Map: Example const fruits = new Map([ ["apples", 500], ["bananas", 300], ["oranges", 200] ]);for (const x of fruits) { // code block to be executed } Try it Yourself » ❮ Previous Next ❯ |
CopyRight 2018-2019 实验室设备网 版权所有 |