JavaScript Array of Objects with For and ForLoop Method

In JavaScript, an array of objects is a common data structure used to group related objects together, each object containing properties with values. This is especially useful for handling complex data sets like lists of users, products, or configurations. Here's how to work with them:

      var student = [
            {name:"ram",age:"39"},
            {name:"kishore",age:"49"},
            {name:"ram",age:"39"},
            {name:"kishore",age:"49"},
            {name:"ram",age:"39"},
        ]

        console.log(student);

        for(var a=1; a<student.length;a++){
            document.write(student[a].name+""+student[a].age+"<br>");
        }

Iterating Over an Object

      var obj ={
            course:"reactjs",
            cdesc:"this is react js course",
            fee:"9999"
        }

        for(var key in obj){
            document.write(obj[key]+"<br>")
        }

Explanation:

  1. for...in: Iterates over all enumerable properties of an object.
  2. person.hasOwnProperty(key): Ensures that only properties belonging to the object itself (not inherited ones) are included.