Array Of Object In Java Script
<html>
<body>
<script>
var n=prompt("Enter the number of employees");
var sample = new Array();
//Input the objects into the array
for(var i=0;i<n;i++)
{
var name=prompt("Enter the name of "+(i+1)+" Employee");
var designation=prompt("Enter the Designation of "+(i+1)+" Employee");
var salary=prompt("Enter the Salary of "+(i+1)+" Employee");
//Enter values into each object
var employee={name:name,designation:designation,salary:salary};
//insert each object into the array
sample.push(employee);
}
//Print the element of object array
for(var j=0;j<n;j++)
{
document.write(sample[j].name+" ");
document.write(sample[j].designation+" ");
document.write(sample[j].salary+" ");
document.write("<br>");
}
</script>
</body>
</html>
#javascript
#arrayofobject
<body>
<script>
var n=prompt("Enter the number of employees");
var sample = new Array();
//Input the objects into the array
for(var i=0;i<n;i++)
{
var name=prompt("Enter the name of "+(i+1)+" Employee");
var designation=prompt("Enter the Designation of "+(i+1)+" Employee");
var salary=prompt("Enter the Salary of "+(i+1)+" Employee");
//Enter values into each object
var employee={name:name,designation:designation,salary:salary};
//insert each object into the array
sample.push(employee);
}
//Print the element of object array
for(var j=0;j<n;j++)
{
document.write(sample[j].name+" ");
document.write(sample[j].designation+" ");
document.write(sample[j].salary+" ");
document.write("<br>");
}
</script>
</body>
</html>
#javascript
#arrayofobject
Comments
Post a Comment