Read object using for -in :- genius student


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

<!DOCTYPE html> 
<html> 
 
<head> 
 <meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 
 
<body> 
 
 <input type="button" value="for in object" onclick="read_objects();"> 
 
 <script> 
  function read_objects() 
  { 
   var ar_ob = []; 
 
   var obj = new Object() 
   obj.name = 'merbin'; 
   obj.mark = 56; 
   ar_ob.push(obj); 
 
   var obj = new Object() 
   obj.name = 'Franklin'; 
   obj.mark = 98; 
   ar_ob.push(obj); 
 
   var obj = new Object() 
   obj.name = 'Ramesh'; 
   obj.mark = 93; 
   ar_ob.push(obj); 
 
   for (i in ar_ob) 
   { 
    alert("Name : " + ar_ob[i].name); 
    alert("Mark : " + ar_ob[i].mark); 
   } 
 
  } 
 </script> 
</body> 
 
</html>
Read object using for -in :- genius student Read object using for -in :- genius student Reviewed by Network security on October 14, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.