How to loop through list of maps to filter out SearchMap key-values from below List having map of records using JS?
Map
var searchMap = new Map()
searchMap.set("ed_mood", "strong")
searchMap.set("ed_target_audience", "Expert")
searchMap.set("ed_clip_type", "intro")
List
var master_data =
[
{ed_mood: "Light", ed_rating: 10, ed_target_audience: "Novice", ed_clip_type: "Basic"},
{ed_mood: "Light", ed_rating: 5, ed_target_audience: "Expert", ed_clip_type: "Q&A"},
{ed_mood: "Strong", ed_rating: 8, ed_target_audience: "Expert", ed_clip_type: "Intro"},
{ed_mood: "Strong", ed_rating: 7, ed_target_audience: "Expert", ed_clip_type: "Q&A"},
{ed_mood: "Strong", ed_rating: 10, ed_target_audience: "Expert", ed_clip_type: "intro"}
]
Note: To filter out record I am using AlaSql but it doesn't give expected result. Any other JS way to filter map to list of maps?
var filter_result = [];
searchMap.forEach(function(value, key){
var data = alasql(`select * from ? where ${key} like ?`,[master_data, `%${value}%`]);
$.each(data, (i) => filter_result.push(data[i]));
});
Expected Result
[
{ed_mood: "Strong", ed_rating: 8, ed_target_audience: "Expert", ed_clip_type: "Intro"},
{ed_mood: "Strong", ed_rating: 10, ed_target_audience: "Expert", ed_clip_type: "intro"}
]