Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Iterating Over a Set

You can use a for…of loop to iterate through the elements of a Set.

Example

const letters = new Set([“a”,“b”,“c”]);

for (const x of letters) {
  // code block to be executed
}

Iterating Over a Map

You can use a for…of loop to iterate through 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
}