Summary: Two ways to define objects in JavaScript
<!doctype html>
<meta charset= "UTF-8" >
<meta name= "Generator" content= "editplus®" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<title>2016-04-06 javascript-Objects </title>
<!--css-->
<style>td{border:1px solid red;text-align:center;width:50px;} </style>
<script>
//object: Define Method 1
var person={
Name: "Tom",
Age: "20",
Sex: "M"
};
//object: Define Method 2
var person1=new Object ();
Person1.name= "John";
Person1.age= "22";
person1.sex= "W";
</script>
<body>
<table>
<tr>
<td> name </td>
<td> Age </td>
<td> Sex </td>
</tr>
<tr>
<TD id= "Name" ></td>
<TD id= "Age" ></td>
<TD id= "Sex" ></td>
</tr>
<tr>
<TD id= "TD4" ></td>
<TD id= "TD5" ></td>
<TD id= "Td6" ></td>
</tr>
</table>
<script>
//Use for: In.. Traversing Object Properties
for (var x in person) {
document.getElementById (x). Innerhtml=person[x];
}
document.getElementById ("Td4"). Innerhtml=person1.name;
document.getElementById ("Td5"). Innerhtml=person1.age;
document.getElementById ("Td6"). Innerhtml=person1.sex;
</script>
</body>
2016-04-06 javascript-Object