How to filter a nested array

156
0
04-20-2024 07:07 PM
Shubhreet
Occasional Contributor
Hello,
 
I am trying to filter a nested array (output_yes) based on conditions from another nested array (output_NF). 
 
My condition for filtering is as such: to filter output_yes when FacilityName and CompleteOutbreakName in output_yes is same as output_NF but DateTimeofSubmission in output_yes is less than (<)  DateTimeofSubmission in output_NF
 
 The following is the code snippet I am able to build so far is as below. My debugging shows that there is an error/issue in the blue colored code line:
 
 
for (var k in output_NF){
  var facility_NF = output_NF[k].attributes.FacilityName;
  var date_NF = output_NF[k].attributes.DateTimeofSubmission;
  var completeOutbreak_NF = output_NF[k].attributes.CompleteOutbreakName;
functionisUndesiredfromOutput_NF(x) {
    return x = "FacilityName = @facility_NF" && "CompleteOutbreakName =@completeOutbreak_NF" && "DateTimeofSubmission<@date_NF" }
  var filter1 = Filter(output_yes, isUndesiredfromOutput_NF);
  for (var s in filter1){
      console (s);}}
 
 
 
My arrays have the similar content as follow:
 
array output_NF contains following values:
 
[{"attributes":{"FacilityName":"Arborg PCH","CompleteOutbreakName":"Respiratory Measles","DateTimeofSubmission":"2023-08-28T18:12:00.000Z","RecentUpdate":"2023-08-28T18:12:00.000Z","OutbreakStatus":"Free of a previously reported outbreak","ObjID":85}},
{"attributes":{"FacilityName":"Concordia Place","CompleteOutbreakName":"Other Scabies","DateTimeofSubmission":"2024-03-26T01:30:00.000Z","RecentUpdate":"2024-03-26T01:30:00.000Z","OutbreakStatus":"Free of a previously reported outbreak","ObjID":97}},}]
 
 
array output_yes contains following values:
 
[{"attributes":{"FacilityName":"Arborg PCH","CompleteOutbreakName":"Gastrointestinal Norovirus","DateTimeofSubmission":"2023-08-29T16:48:00.000Z","RecentUpdate":"2023-08-29T16:48:00.000Z","OutbreakStatus":"Yes","ObjID":88}},
{"attributes":{"FacilityName":"Arborg PCH","CompleteOutbreakName":"Respiratory Measles","DateTimeofSubmission":"2023-04-03T18:43:00.000Z","RecentUpdate":"2024-04-03T18:43:00.000Z","OutbreakStatus":"Yes","ObjID":100}},
{"attributes":{"FacilityName":"Concordia Place","CompleteOutbreakName":"Multidrug-Resistant Organism (MDRO) MRSA","DateTimeofSubmission":"2024-03-26T00:22:00.000Z","RecentUpdate":"2024-03-26T00:22:00.000Z","OutbreakStatus":"Yes","ObjID":96}},
{"attributes":{"FacilityName":"Concordia Place","CompleteOutbreakName":"Other Scabies","DateTimeofSubmission":"2023-08-03T18:27:00.000Z","RecentUpdate":"2023-08-03T18:27:00.000Z","OutbreakStatus":"Yes","ObjID":75}},]
 
 
 
0 Kudos
0 Replies