How to create an object with property value as an object in JavaScript

1 Answer

0 votes
const worker = {
    id: 836746,
    department: {
        area: 4,
        room: 16
    },
    show: function() {
        console.log(this.id + ' ' + this.department.area + ' ' + this.department.room);
    }
}


worker.show();



/*
run:

836746 4 16

*/

 



answered Mar 4, 2020 by avibootz
...