1

I want to call name property in another key. Is it possible? If yes, then how can we achieve this?

let user = {
        name: "John",
        age: this.name,  
      };
      console.warn(user)
Philosophist
  • 103
  • 1
  • 13
anil sidhu
  • 963
  • 1
  • 9
  • 24

2 Answers2

0

Do you mean like this? What is it you are trying to achieve?

let userA = {
        name: "John",
        age: 8 
      };
      
let user = {
        name: "John",
        age: userA.name 
      };
console.log(user)
Bibberty
  • 4,670
  • 2
  • 8
  • 23
0

I am not in a position to test it at the moment, but I think, in theory, this should work:

let user = { 
  name: "John" 
}; 
user.age = user.name
console.log(user.age);
// output: John
Philosophist
  • 103
  • 1
  • 13