Javascript logical operation

Hi All, I’ve 2 JSON arrays and 1 date to indicate the key, how to make it in one line per date basis?

var a = ['Nov 1 2016','Nov 2 2016','Nov 3 2016','Nov 4 2016'];
var b = [{Date:'Nov 1 2016', steel:10.98},{Date:'Nov 3 2016', steel:5.67},{Date:'Nov 4 2016', steel:3.14}]
var c = [{Date:'Nov 1 2016', concrete:9.10},{Date:'Nov 2 2016', concrete:16.8},{Date:'Nov 4 2016', concrete:7.20}]

//output sum of steel and concrete
var x  =  [{Date:'Nov 1 2016', val:20.08},{Date:'Nov 2 2016', val:16.8},{Date:'Nov 3 2016', val:5.67},{Date:'Nov 4 2016', val:10.34}]

Thank you in advance!

I don’t think I understand your question.
Are you trying to create another object dynamically from the sum of each day?

//Some keys are missing so I assigned them zero
var dates = 
  { 
    "Nov 1 2016": {
      "steel": 10.98,
      "concrete": 9.10
    },
    "Nov 2 2016": {
      "steel":0,
      "concrete": 16.8
    },
    "Nov 3 2016":{
      "steel": 5.67,
      "concrete": 0,
    },
    "Nov 4 2016": {
      "steel": 3.14,
      "concrete": 7.20
    } 
  };
//Loop through:
for(var x in dates){
  console.log(dates[x].steel + dates[x].concrete);
}

If I understood the question well, the console of the above code will produce the values, so you just need to assign each value and create another object from the value…

Happy Coding!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.