1
var user = {
  firstName: "Jenish",
  lastName:"Patel",
  fullName: user.firstName + user.lastName //how to access this values?
  // I want to directly access current key values here.
};
console.log(user.fullName);

expected output:

"Jenish Patel"

Note: I already know that I can do something like

user['fullName'] = user['firstName'] + user['lastName']

But can we achieve this within an object? I want to achieve in this way because I am working with large and multiple JSON objects in which the above is not convenient to use and it also not give good readability.

Intervalia
  • 10,248
  • 2
  • 30
  • 60
Chirag Kalal
  • 638
  • 1
  • 7
  • 21

0 Answers0