Java Reference
In-Depth Information
superman
<< {"allies": ["Batman", "Supergirl", "Superboy"], "city":
↵
"Metropolis", "fly": function (){
console.log("Up, up and away!");
}, "height": 75, "hero": true, "name": "Superman", "real
name":
↵
"Kal-El", "villain": false, "weight": 235}
Removing Properties
Any property can be removed from an object using the
delete
operator. For example,
if we wanted to remove the
fly
method from the
superman
object, we would enter the
following:
delete superman.fly
<< true
Now if we take a look at the
superman
object, we can see that he has lost his ability to
fly:
superman
<< {"allies": ["Batman", "Supergirl", "Superboy"], "city":
↵
"Metropolis", "height": 75, "hero": true, "name":
"Superman",
↵
"real name": "Kal-El", "villain": false, "weight": 235}
Nested Objects
It's even possible for an object to contain other objects. These are known as
nested objects
.
Here's an example of an object that contains a list of other objects. It has been assigned to
the variable
jla
:
jla = {
superman: { realName: "Clarke Kent" },
batman: { realName: "Bruce Wayne" },
wonderWoman: { realName: "Diana Prince" },
