Each one of my Object
's properties has the common property (called: selected
), is there a short way to inject this property to each one of the properties without explicitly write each one?
note that I've already looked through this answer but its only talking about arrays
var myObject = {
propery1: {
selected: function () {
return this.value === someVariable;
},
value: 1,
},
propery2: {
selected: function () {
return this.value === someVariable;
},
value: 2,
},
propery3: {
selected: function () {
return this.value === someVariable;
},
value: 3,
},
//...
propery10: {
selected: function () {
return this.value === someVariable;
},
value: 10,
},
};
For example:
var someVariable = 1;
OUTPUT:
myObject = {
propery1: {
selected: true,
value: 1,
},
propery2: {
selected: false,
value: 2,
},
propery3: {
selected: false,
value: 3,
},
//...
propery10: {
selected: false,
value: 10,
},
};