I need to compare two arrays
and when records match then save mached record to another array
Array1 =
[ { "phId": 10, "value": "[PACKNAME]" }, { "phId": 11, "value": "[PACKTYPE]" }, { "phId": 12, "value": "[BALANCE]" }, { "phId": 17, "value": "[DURATION]" } ]
Array2 =
[ "[PACKNAME]", "[BALANCE]" ]
Matched Record Saved Array
[ { "phId": 10, "value": "[PACKNAME]" }, { "phId": 12, "value": "[BALANCE]" } ]
How can I achive this approch using javascript.
I could do matching and save array for same kind of arrays using below code but I'm unable to do above scenario.
let firstArray = ["One", "Two", "Three", "Four", "Five"];
let secondArray = ["Three", "Four"];
let map = {};
firstArray.forEach(i => map[i] = false);
secondArray.forEach(i => map[i] === false && (map[i] = true));
let jsonArray = Object.keys(map).map(k => ({ name: k, matched: map[k] }))