0

I would like to filter a json object by it's values and I have two words as the key which is not working for my code.

This works fine:

let age_group = ["D31+", "D8-D30"];
let obj;
obj = [{"Age": "D0-D7"},
       {"Age": "D8-D30"},
       {"Age": "D31+"}];
console.log(obj.filter(({ Age }) => age_group.includes(Age)));

but this does not work

let age_group = ["D31+", "D8-D30"];
let obj;
obj = [{"Age Group": "D0-D7"},
       {"Age Group": "D8-D30"},
       {"Age Group": "D31+"}];
console.log(obj.filter(({ Age Group }) => age_group.includes(Age Group)));

I tried backticks as well but it did not work either

Pascal Schmidt
  • 223
  • 2
  • 12

0 Answers0