Adding property to another property

why when adding a property to another property I get undefined error

var object={};
object["test"]= 404;
console.log(object);

{ test: 435 }          // Output

The above works fine, But when I try to add more property so as to have more phase of properties I receive undefined error.

var object={};
object["test"]["why"]= 404;
console.log(object);

TypeError: Cannot set property 'why' of undefined  // Output

Expected the below output

{ test: why: 435 }

67 thoughts on “Adding property to another property”

Leave a Comment