如何基于其他属性计算对象文字中的对象属性

时间:2016-11-09 05:06:26

标签: javascript

我在json中减去这可能吗?

 @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"
}

1 个答案:

答案 0 :(得分:1)

我在你的问题中假设]。没有这个是不可能的。



 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);