0
const object1 = {
    firstName : 'Shashidhar',
    lastName : 'B M ',
    rollNo : 5678,
    rank : 23456

}

Object.defineProperties(object1,{
    property1 : {
    results : 'selected'
    }
});


console.log(object1.property1)
console.log(object1.firstName);

expected output

selected
shashidhar

actual output

undefined
shashidhar
evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
SBM
  • 17
  • 4
  • 4
    You don't seem to be using `defineProperties` correctly? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties Consider using `value` instead of `results`? – evolutionxbox Dec 30 '22 at 14:13
  • I think, per the [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties), you need to set `value`. `results` doesn't seem to be valid. – mykaf Dec 30 '22 at 14:14

1 Answers1

0

You want value rather than results to specify the property's value:

const object1 = {
    firstName : 'Shashidhar',
    lastName : 'B M ',
    rollNo : 5678,
    rank : 23456
}

Object.defineProperties(object1,{
    property1 : {
    value : 'selected'
    }
});


console.log(object1.property1)
console.log(object1.firstName);

See the documentation on MDN.

Robin Zigmond
  • 17,805
  • 2
  • 23
  • 34