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
  • 9,298
  • 1
  • 27
  • 53
Chirag Kalal
  • 558
  • 5
  • 19

0 Answers0