How can i find a single object which is nested deeply in an array? This is the code which works. But [0] isnt really save when it returns null or an empty array.
this.subscription = state.subscriptionsState.subscriptions
.map(subs => subs.subscriptions.find(sub => sub.id === subscriptionId))[0];
Is there a better / nicer way?
edit: input data:
state.subscriptionsState.subscriptions = [
{
"name": "name",
"type": "type",
"subscriptions": [{
"id": 123456,
}]
}
]
.map()[0]can be replaced by.find()findinstead ofmapi need to return a bool in the "second"find.