JS For Of

The for...of loop is used to iterate over iterable objects, such as arrays, strings, maps, sets, and more. It directly provides the values of the iterable.


Syntax:

for (element of iterable) {
    // Code to execute for each element
}


  • element: A variable that stores the value of the current item in the iteration.
  • iterable: An object that can be iterated (e.g., an array, string, or other iterable).
Iterating Over an Array
let numbers = [10, 20, 30, 40];

for (let number of numbers) {
console.log(number);
}

Try it yourself


Iterating Over a String
let str = "hello";

for (let char of str) {
console.log(char);
}

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.