如何将一个对象中的两个值相乘

时间:2018-10-24 12:41:34

标签: javascript jquery jquery-plugins

我在JSON数据中包含此表:

enter image description here

我想做:Res [i] = Code[i] * Code_V[i];

我的脚本是:

get_full_Res  = function(obj)  {
  $.each(obj, function() {
    $.each(this, function(k, v) {
      console.log("k : "+k+" v: "+v)
    });
  });
}

在遍历JSON数据后,我不知道如何使用jQuery。请帮助

1 个答案:

答案 0 :(得分:0)

Your object is like 
var obj = [{
    "Name": "X0012",
    "Ps": "PO10",
    "Code": 31,
    "Code_V": 10,
    "Res": 0
}, {
    "Name": "X0013",
    "Ps": "PO11",
    "Code": 22,
    "Code_V": 11,
    "Res": 0
}, {
    "Name": "X0014",
    "Ps": "PO12",
    "Code": 1,
    "Code_V": 12,
    "Res": 0
}];
then we can use for loop here

for(var k in obj)
{
  console.log(obj[k].Code * obj[k].Code_V);
}