I have to remove the elements from arrayOne which is exists in arrayTwo, but I have to remove those records which is matched at first occurrences only. Remaining records should present ass it is if still they matched.
let arrayOne = [
{variantnames: 'Testing', variantvalues: '20', forDate: '2022-09-29'},
{variantnames: 'free suger', variantvalues: '10', forDate: '2022-09-29'},
{variantnames: 'chocolate', variantvalues: '15', forDate: '2022-09-29'},
{variantnames: 'chocolate', variantvalues: '15', forDate: '2022-09-29'},
{variantnames: 'Testing', variantvalues: '20', forDate: '2022-09-29'},
{variantnames: 'free suger', variantvalues: '10', forDate: '2022-09-29'},
];
let arrayTwo = [
{variantnames: 'Testing', variantvalues: '20', forDate: '2022-09-29'},
{variantnames: 'free suger', variantvalues: '10', forDate: '2022-09-29'}
];
let result = arrayOne.filter(o1 => !arrayTwo.some(o2 => o1.variantnames == o2.variantnames));
console.log("result", result);
I know, we shold have to use findIndex to remove matched records from arrayOne but not able to get result.
Expected output should be
result = [
{variantnames: 'chocolate', variantvalues: '15', forDate: '2022-09-29'},
{variantnames: 'chocolate', variantvalues: '15', forDate: '2022-09-29'},
{variantnames: 'Testing', variantvalues: '20', forDate: '2022-09-29'},
{variantnames: 'free suger', variantvalues: '10', forDate: '2022-09-29'},
];
arrayTwohas two entries inarrayOnewith the same values.