I am working with an array of objects that contain nested arrays of objects, similar to what is shown in Code snippet 1
.
My goal is to calculate the number of records within the nested array where the parent_user_id
matches the id
. Based on this criteria, from Code snippet 1
the count should be 4, and the total count should include iterating through similar outer array of objects.
**Code Snippet 1**
[
{
"name" : "A",
"description" : null,
"users" : [
{
"id" : "63a8808c52f40e1d48a3d1da",
"owner" : "John Doe",
"purchase_date" : "2022-12-25,
"status" : "active",
"parent_user_id" : "63a8808c52f40e1d48a3d1da",
"recent_items": ["tomato",onion]
},
...
]
}
]
I have attempted solutions involving loops and iteration, but I am wondering if there is a simpler way to accomplish this task using JavaScript or Typescript?