Read array value using for...of in javascript

     for of loop was introduced in ES6 which allows you to easily iterate over elements of an collection.for of iterates over the values of elements of a collection not the keys. A collection can be an array, set, list, custom collection object etc.

     Earlier to ES6 we had to use for loop or Array’s foreach loop to walkthrough elements of an collection. ES6 introduced a new way for iteration.

Syntax

    for (variable of array_or_object)

    {

       Statements;

    }


Example

    var ar = [2, 4, 5, 2, 7, 48, 234];



    for (i of ar)

    {

      alert(i);

    }


Example Program:- (Editor)


Editor is Loading...

Advertisement




Tags:
javascript for of in allinworld99, allinworld99 to read array value, javascript to read array value using for of in allinworld99

0 nhận xét:

Đăng nhận xét