[
{
_id: "646231c54574e0e7ffc569e9",
users: [
{
_id: "6461ef44496eff14402778af",
name: "Salman Khan"
},
{
_id: "6461f15bb4e0a6c7addc9fb0",
name: "Yash Sharma"
{
_id: "646211fac7359b7ed8f27bcb",
name: "abcd",
]
}
]
I have an array with items like the above one. Now, I want to get that element which containes two specific _id
in it’s users
array.
2
Answers
Start by semantically describing what you’re trying to accomplish:
Third condition added based on a comment above: "I’m looking for elements which only have two values not any other value."
The description essentially defines the logic. For example:
You can use filter method in combination with every element which will loop through your in put array and check if that is exists in each of the users array.