I have this 2 array :
let filterdata = [
{
"value": "item",
"text": "additional_image_link",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "url",
"text": "adwords_grouping",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "campaign_id",
"text": "id",
"custom": null,
"updates": true,
"removes": true
}
];
let newdata = [
{
"value": "item",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "url",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "campaign_id",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "campaign_url",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "luck",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "okay",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "nope",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "brand",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
}
]
I want to marged this 2 array and the output should be like that:
[
{
"value": "item",
"text": "additional_image_link",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "url",
"text": "adwords_grouping",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "campaign_id",
"text": "id",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "campaign_url",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "luck",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "okay",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "nope",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
},
{
"value": "brand",
"text": "do_not_import",
"custom": null,
"updates": true,
"removes": true
}
]
I am trying this :
let final = newdata.filter( ( item, index ) => {
return item.text === 'do_not_import' && filterdata.hasOwnProperty( 'text' ) !== 'do_not_import' ;
});
console.log( final )
but no luck :(
Merged Logic:
You can see that filterdata value key is exist in newdata but in newdata text value is do_not_import and in filterdata text value is not do_not_import.
so in that case, its should remove the those filterdata from the newdata.
filter, which is used to filter an array for elements that don't match your criteria, and can't generate new kinds of data, only "keep what you already have, or throw things away"?