如何将算术和二进制运算转换为各自的符号和值

How to convert Arithmetic and binary operation to their respected symbols & values

我正在从后端获取 JSON 值。我面临着价值转换的问题。我得到的值为 greaterThan,我应该将其显示为 >,我的状态为 1,我需要在我的前端将其显示为 on .我怎样才能做到这一点? 以下是我的 JSON 值

{fact: "s1", operator: "greaterThan", value: 8, status: "on", $$hashKey: "object:52"}

需要的输出应该转换成这种格式

{fact: "s1", operator:">", value: 8, status: 1, $$hashKey: "object:52"}

试试这个,

var data = [{
  fact: "s1",
  operator: "greaterThan",
  value: 8,
  status: "on",
  $$hashKey: "object:52"
}];

data = data.map((val) => {
  if (val.operator == "greaterThan")
    val.operator = '>';
  if (val.status == 1)
    val.operator = 'on';
  return val;
});

console.log(data);

$scope.json = [{
  "fact": "s1",
  "operator": "greaterThan",
  "value": 8,
  "status": "on",
  "$$hashKey": "object:52"
}];

angular.forEach($scope.json, function(value, key) {
    if (value.operator == "greaterThan")
        value.operator = '>';

    if (value.status == 1)
        value.operator = 'on';

    return value;
})