There's a way to do a request.except([]) in an array of objects?

I’m receiving from my frontend this data:

[
{
“id”: 1,
“description”: “Cadastro de usuários”,
“screen_id”: 1,
“allow_read”: true,
“allow_create”: true,
“allow_update”: false,
“allow_delete”: true
},
{
“id”: null,
“description”: “Tela teste 3”,
“screen_id”: 5,
“allow_read”: false,
“allow_create”: false,
“allow_update”: true,
“allow_delete”: false
},
{
“id”: null,
“description”: “Tela teste 4”,
“screen_id”: 6,
“allow_read”: false,
“allow_create”: false,
“allow_update”: false,
“allow_delete”: false
}
]

There’s a way to don’t catch the description property in all objects?
I try:

let permissions = request.except(['description'])

But my objects still have this property. This works when is not a array. There’s a way to do this in a array?

1 Like

Before sending data to the backend or on receiving from the frontend, you can do the following:

let data = [
{
“id”: 1,
“description”: “Cadastro de usuários”,
“screen_id”: 1,
“allow_read”: true,
“allow_create”: true,
“allow_update”: false,
“allow_delete”: true
},
{
“id”: null,
“description”: “Tela teste 3”,
“screen_id”: 5,
“allow_read”: false,
“allow_create”: false,
“allow_update”: true,
“allow_delete”: false
},
{
“id”: null,
“description”: “Tela teste 4”,
“screen_id”: 6,
“allow_read”: false,
“allow_create”: false,
“allow_update”: false,
“allow_delete”: false
}
];

data = data.map((item) => {
  delete item.description;
  return item;
});
2 Likes

Also you can use omit method from lodash.

return _.omit(permissions, ['description']);

https://lodash.com/docs/4.17.15#omit

2 Likes