I have an array like this:
parent = [
{'id':'id_1','level':'1-1','children':['id':'id_1','level':'1-1-0','children':[........]},
{'id':'id_2','level':'2-2','children':['id':'id_1','level':'2-1-0','children':[........]}
]
How can I get the parent array index that match the condition of child array object
For example:
If (level == '2-1-0')
Output: 1
Expected Behaviour:
It should return 1 because level 2-1-0 present in 1'st index of parent array
Note: I tried like below
var index = parent .findIndex(data => data.level== result.level);
It will not check child array object
parentvariable is syntactically invalid: can you update your question? Also, is there arbitrary level of nesting forchildren?result.level.childrenarray is not a va;id array. Also is its just to find the matching level from the child objects in the array? Asking this specifically because you children array already have an another children node.