user[userid = uid].cards[cardTitle = cdTitle].tasks
Firstly, the array indexer expects the index of the item to return. It does not accept an expression to match a specific item.
Secondly, you are using the assignment operator (
) to copy the existing variables (
) to new previously-undefined variables (
). That's not going to filter the items in any way.
You'll need to use a combination of filter
] and flatMap
] to perform your query. You'll also need to use optional chaining
] to avoid an error if the item you're searching for doesn't exist.
const tasks = user.filter(u => u.userid === uid)?.flatMap(u => u.cards.filter(c => c.cardTitle === cdTitle))?.flatMap(c => c.tasks);