in

JavaScript For Of

Ghana's No. 1 Premier Resource For News, Politics, Sports, Business, Entertainment, Showbiz ,Photos, Music, Videos & Movies.

become a member

JavaScript For Of

The For/Of Loop

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

Download Latest Movies in Single Click For All Devices in 720p and 1080p.Download Movies

It lets you loop over iterable data structures such as Arrays, Strings, Maps, NodeLists, and more:

Syntax

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

variable – For every iteration the value of the next property is assigned to the variable. Variable can be declared with constlet, or var.

iterable – An object that has iterable properties.


Browser Support

For/of was added to JavaScript in 2015 (ECMAScript 2015)

Safari 7 was the first browser to support for/of:

Chrome 38 Edge 12 Firefox 51 Safari 7 Opera 25
Okt 2014 Jul 2015 Oct 2016 Oct 2013 Oct 2014

For/of is not supported in Internet Explorer.


Looping over an Array

Example

let cars = [“BMW”“Volvo”“Mini”];
let text = “”;

for (let x of cars) {
text += x + “<br>”;
}

Try it Yourself »


Looping over a String

Example

let language = “JavaScript”;
let text = “”;

for (let x of language) {
text += x + “<br>”;
}

Try it Yourself »



The While Loop

The while loop and the do/while loop are explained in the next chapter.

Thank you for reading; when you read and give feedback, we get one more chance to write one more story and don't forget to Share on favorite Social media network.

youtube follow ustwitter follow us

What do you think?

Written by bawaeric

Cefuroxime, Oral Tablet

Nalerigu Nurses Training College Entertainment Prefect arrested over twerking competition for 1st years

Nalerigu Nurses Training College Entertainment Prefect arrested over twerking competition for 1st years