Properties are defined as the values that are associated with a JavaScript object.It is also called the very important part of Javascript.
A JavaScript object is made up of a collection of un-ordered properties.It can be changes, added, deleted.
syntax for using property of an object is:
objectName.property // person.height
OR
objectName["property"] // person["height"]
OR
objectName[expression] // a = "height"; person[a]
Exapmle of JavaScript for in loops through the properties of an object. In this example the for in loop will execute once for each property.
<p id="property"></p>
<script>
var txt = "";
var name = {fname:"A123", lname:"B123", age:25};
var x;
for (x in name) {
txt += name[x] + " ";
}
document.getElementById("property").innerHTML = txt;
</script>
0 Comment(s)