JavaScript Iterables 您所在的位置:网站首页 青铜峡黄河楼花了多少钱 JavaScript Iterables

JavaScript Iterables

#JavaScript Iterables| 来源: 网络整理| 查看: 265

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 Loop

The JavaScript for..of statement loops through the elements of an iterable object.

Syntax for (variable of iterable) {   // code block to be executed } Iterating

Iterating 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 String

You 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 Array

You 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 Set

You 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 Map

You 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 实验室设备网 版权所有