I want to filter from two different arrays based on following array named = timeArray
["13:37", "13:36", "13:35", "13:34", "13:33", "13:32"]
first array looks like this .. array1
[
[23323.25,23323.65,23313.25,23315.05,97,62,"13:36"],
[23315.05,23315.2,23314,23315,8,9,"13:37"]
]
second array looks like this .. array2
[
[23310,23310,23300,23300,0,0,"13:34"],
[23309.75,23343.1,23305,23323.25,0,0,"13:35"],
[23296.5,23310,23294.65,23309.8,0,0,"13:30"],
[23308.35,23310,23301,23306.15,0,0,"13:31"],
[23308,23309,23292.5,23299.55,0,0,"13:32"],
[23299.55,23310,23294.15,23310,0,0,"13:33"],
[23310,23310,23300,23300,0,0,"13:34"],
[23309.75,23343.1,23305,23324.65,0,0,"13:35"],
[23308,23309,23292.5,23299.55,0,0,"13:36"]
]
Based on Timearray elements, First should check array1 and then array 2 6th element and expected result should look like
[
[23308,23309,23292.5,23299.55,0,0,"13:32"],
[23299.55,23310,23294.15,23310,0,0,"13:33"],
[23310,23310,23300,23300,0,0,"13:34"],
[23309.75,23343.1,23305,23324.65,0,0,"13:35"],
[23323.25,23323.65,23313.25,23315.05,97,62,"13:36"],
[23315.05,23315.2,23314,23315,8,9,"13:37"]
]
I tried something like below
var finalarray = [];
for(var key in timeArray)
{
var timer = timeArray[key];
for(var key in array1)
{
arraytime1 = array1[key][6];
if(timer == arraytime1)
{
finalarray.push(arraytime1);
}
}
for(var key in array2)
{
arraytime2 = array2[key][6];
if(timer == arraytime2)
{
finalarray.push(arraytime2);
}
}
}
But "13:36" is added two times...Also if the element based on timerArray is not present it should be null... also is there any better way to do it ? I feel like it takes much resource to process... Thank you.
array1andarray2, as13.36in your example. You should keep the one inarray1? You should sum them? You should keep the bigger one? I don't knowfor ... inloop instead of takinging elements with either an index or withfor ...of.