I like to think I understand JavaScript, but I found something unexpected today and I was hoping someone could explain to me why it happens.
Take this code
var animalData = {
                  cow:"cow",
                  sheep:"sheep",
                  getCow:function()
                  {
                    return this.cow;
                  },
                  animalList:[
                          {
                            animalId:this.cow,
                            label:"This is a cow"
                          },
                          {
                            animalId:this.sheep,
                            label:"This is a sheep"
                          }
                       ]
          };
console.log(animalData.getCow());
console.log(JSON.stringify(animalData.animalList,null," "))
The output is not what I was expecting. Calling animalData.getCow() results in "cow" just as you would expect. But it's what gets return by the second console.log that confuses me.
[
 {
  "label": "This is a cow"
 },
 {
  "label": "This is a sheep"
 }
]
In other words, the object removes the animalId property entirely from the objects defined. I was expecting this
[
 {
  "animalId":"cow",
  "label": "This is a cow"
 },
 {
   "animalId":"sheep",
  "label": "This is a sheep"
 }
]
And I could understand maybe this
[
 {
   "animalId":undefined,
  "label": "This is a cow"
 },
 {
   "animalId":undefined,
  "label": "This is a sheep"
 }
]
But why does the animalId property get removed entirely?
Can anyone explain what's going on under the surface to cause this behaviour? I'm guessing that the this keyword does not work because the properties are undefined when it is invoked, but why does it remove the property entirely? 
NB: I'm not looking for a workaround, that's easy enough to do - just interested in why it happens.
console.logto see the effect of stringifying this object, not that he's stringifying it to log it.var o = { x: {y: 3}}; console.log(o); o.x.y = 5;when it was logged,o.x.ywas 3, but when you expand it, you see it shows as 5.