S
S
Sergey questions2018-07-16 20:04:29
JavaScript
Sergey questions, 2018-07-16 20:04:29

How to correctly compare arrays and replace if the key matches?

Hello. There are 2 arrays.
In the first array - a range of dates and zero values, in the second - an array of some dates with positive values.

array1 =[];
array1.push(['Days', 'Sales', 'Expenses']);
array1.push(["2018-07-10",0,0]);
array1.push(["2018-07-11",0,0]);
array1.push(["2018-07-12",0,0]);
array1.push(["2018-07-13",0,0]);
array1.push(["2018-07-14",0,0]);
array1.push(["2018-07-15",0,0]);
array1.push(["2018-07-16",0,0]);

array2 =[];
array2.push(['Days', 'Sales', 'Expenses']);
array2.push(["2018-07-10",3,580]);
array2.push(["2018-07-13",1,1200]);
array2.push(["2018-07-16",6,160]);

How can I combine these 2 arrays to get the same date range but with the values ​​from the second array where they are?
Non jsfiddle example : https://jsfiddle.net/mupfgbx0/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Egorov, 2018-07-16
@smartycms

https://jsfiddle.net/Svupol/mupfgbx0/9/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question