How to remove an item dynamically from an object?

Asked

Viewed 78 times

0

I’m using a state of reducer, containing an object in this format:

x = {10: {nome: 'lucas'}, 20:{nome: 'beraldo'}} <br/>

And, I get an id via action.

I’d like to do something like array.filter, or the delete only dynamically on this object, to remove an item, for example:

delete x.actionID

Only he can’t understand the action.ID, since it’s coming from the action.

If it were an array, it would x = x.filter(nome != action.id), but since it’s an object, I don’t know how to treat.

  • Have you tried delete x[actionID];?

1 answer

1


You can delete by key:

delete x[actionID]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.