I have a JSON object that I want to remove a series of items from:
const addressNonRequired = ["addr_linkid_usr", "addr_created", "addr_updated"]
I know I can use the 'delete' method, but how would I use the above array to do the same:
// remove non-required data
addressesFound.forEach(row => (
// delete row.addr_linkid_usr,
// delete row.addr_created,
// delete row.addr_updated
addressNonRequired.forEach(item => (
delete row[item];
));
));
I've tried several ways to get this to work, not sure if I'm looking at it the right way .... ?
Example of array provided:
[
{
"addr_id": "41d86d46-8b19-4f4e-be03-f9915ef4947b",
"addr_type": "postal",
"addr_linkid_usr": "user1",
"addr_created": "2021-03-10",
"addr_updated": "",
"addr_active": true,
"addr_postal_as_residential": false,
"addr_international": false,
"addr_autocomplete_id": null
},
{
"addr_id": "b18c2ca6-29cf-4114-9067-b37fd3394638",
"addr_type": "residential",
"addr_linkid_usr": "user1",
"addr_created": "2021-03-10",
"addr_updated": "",
"addr_active": true,
"addr_postal_as_residential": true,
"addr_international": true,
"addr_autocomplete_id": "string"
}
]
Expected output:
[
{
"addr_id": "41d86d46-8b19-4f4e-be03-f9915ef4947b",
"addr_type": "postal",
"addr_active": true,
"addr_postal_as_residential": false,
"addr_international": false,
"addr_autocomplete_id": null
},
{
"addr_id": "b18c2ca6-29cf-4114-9067-b37fd3394638",
"addr_type": "residential",
"addr_active": true,
"addr_postal_as_residential": true,
"addr_international": true,
"addr_autocomplete_id": "string"
}
]
addressesFoundArgument of type 'Address' is not assignable to parameter of type 'string'.