i have arrays, 1 array is master data and other array which contains pipe seperated value. please find below the code for the same
var master = [
{id:1, value:'John'},
{id:2, value:'Bobby'}
];
var names = [
{id:1, name:'Sandra|John', type:'user', username:'sandraJ'},
{id:2, name:'John', type:'admin', username:'johnny2'},
{id:3, name:'Peter|John', type:'user', username:'peteJ'},
{id:4, name:'Bobby', type:'user', username:'be_bob'},
{id:4, name:'Peter1|John1', type:'user', username:'be_bob'}
];
The resultant output should be the following
var result3 = [
{id:1, name:'Sandra'},
{id:2, name:'Peter'},
{id:2, name:'Peter1|John1'}
];
I tried following ES6 version but it does not throw the expected output.
let result = names.filter(o1 => !master.some(o2 =>
o1.name.split('|').includes(o2.value)));
i also tried replacing some with every, but still it doesn't work
let result = names.filter(o1 => !master.every(o2 =>
o1.name.split('|').includes(o2.value)));
can someone please help me with the same?
idfrom, what happens withname?