Add properties to an Object in JavaScript

Description

The following code shows how to add properties to an Object.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
<!--   ww w .  j  a  v a  2  s.  co  m-->
var person = new Object();
person.name = "JavaScript";
document.writeln(person.name); //"JavaScript"


</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Add properties to an Object in JavaScript