compare value between two values from array in javascript code example
Example 1: how to compare two arrays and return the missing values
var a1 = [1,2,3,4,5,6];
var a2 = [1,3,5];
var absent = a1.filter(e=>!a2.includes(e));
console.log(absent);
Example 2: javascript find matching elements in two arrays
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] }));