Read object using for- of :- genius student


  • for-of can read all values in a object one by one without using its length.
  • Loop execute until get last value of the object.

  • Code:-

    1. <!DOCTYPE html> 
    2. <html> 
    3.  
    4. <head> 
    5.  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    6. </head> 
    7.  
    8. <body> 
    9.  
    10.  <input type="button" value="for of object" onclick="read_objects();"> 
    11.  
    12.  <script> 
    13.   function read_objects() 
    14.   { 
    15.    var ar_ob = []; 
    16.  
    17.    var obj = new Object() 
    18.    obj.name = 'merbin'; 
    19.    obj.mark = 56; 
    20.    ar_ob.push(obj); 
    21.  
    22.    var obj = new Object() 
    23.    obj.name = 'Franklin'; 
    24.    obj.mark = 98; 
    25.    ar_ob.push(obj); 
    26.  
    27.    var obj = new Object() 
    28.    obj.name = 'Ramesh'; 
    29.    obj.mark = 93; 
    30.    ar_ob.push(obj); 
    31.  
    32.    for (i of ar_ob) 
    33.    { 
    34.     debugger; 
    35.     alert("Name : " + i.name); 
    36.     alert("Mark : " + i.mark); 
    37.    } 
    38.  
    39.   } 
    40.  </script> 
    41. </body> 
    42.  
    43. </html>
    Read object using for- of :- genius student Read object using for- of :- genius student Reviewed by Network security on October 18, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.