Gerome John Pangan Gerome John Pangan - 1 month ago 10
Javascript Question

How to compute object properties in object literal based on other properties

I'm doing to subtract inside the json is this possible?

@employees = [
{
"name": "Fullname1"
"vl": "Vacation Leave",
"vl_days": "15.0",
"sl": "Sick Leave",
"sl_days": "10.0",
"bday": "Birthday",
"b_day":"1.0",
"credit_vl":"12.0",
"use_vl": "vl_days - credit_vl"
}

Answer

i am assuming ]in your question . without this it is not possible.

 employees = [
{
  "name": "Fullname1",
  "vl": "Vacation Leave",
  "vl_days": "15.0",
  "sl": "Sick Leave",
  "sl_days": "10.0",
  "bday": "Birthday",
  "b_day":"1.0",
  "credit_vl":"12.0"
}];
var use_vl=(employees[0].vl_days-employees[0].credit_vl);
 employees[0].use_vl=use_vl;

console.log(employees);