xxxxxxxxxx
let haveItList = ['apples', 'milk', 'bread', 'peanutbutter'];
let wishList = ['cookies', 'bread', 'jam', 'peanutbutter', 'bananas', 'cheese'];
let inBothLists = wishList.filter(element => haveItList.includes(element));
// inBothLists = ['apples', 'bread', 'peanutbutter'];
xxxxxxxxxx
var arr1 = [
{
"prop1": "value1",
"prop2": "value2",
},
{
"prop1": "value3",
"prop2": "value4",
},
{
"prop1": "value5",
"prop2": "value6",
},
];
var arr2 = ['value1','value3', 'newValue'];
// finds all the elements of arr2 that are not in arr1
arr2.filter(
val => !arr1.find( arr1Obj => arr1Obj.prop1 === val)
); // outputs "newValue"
xxxxxxxxxx
// elements to filter out.
const keys = [['a','b','c']],
keySet = new Set(keys[0]),
// example data.
data = [['a',1,2],
['c',4,3],
['d',3,4]],
out = data.filter(([item0])=>!keySet.has(item0));
console.info(out);
xxxxxxxxxx
const ObjectOfKeys = keys.reduce((acc,rec)=> {
let nextAcc = acc;
nextAcc[rec] = true;
return nextAcc;
},{});
const filteredData = data.filter(rec => !ObjectKeys[rec[0]])
xxxxxxxxxx
const ObjectOfKeys = keys.reduce((acc,rec)=> {
let nextAcc = acc;
nextAcc[rec] = true;
return nextAcc;
},{}};
const filteredData = data.filter(rec => !ObjectKeys[rec[0]])
xxxxxxxxxx
const ObjectOfKeys = keys.reduce((acc,rec)=> {
let nextAcc = acc;
nextAcc[rec] = true;
return nextAcc;
},{}};
const filteredData = data.filter(rec => !ObjectOfKeys[rec[0]])
xxxxxxxxxx
const ObjectOfKeys = keys.reduce((acc,rec)=> {
let nextAcc = acc;
nextAcc[rec] = true;
return nextAcc;
},{});
const filteredData = data.filter(rec => !ObjectOfKeys[rec[0]])