Find an element in an array recursively

后端 未结 3 1368
情深已故
情深已故 2021-01-04 05:55

I have an array of objects. Every object in the array has an id and an item property that is an array containing other object. I need to be able to find an element in an arr

3条回答
  •  太阳男子
    2021-01-04 06:26

    yeah thanks but I have an issue if there is a nested array like you wanna build a menu panel yourself and wanna get an item with a specific id no matter where is it

    example : var treeDataSource = [ { Id: 1, Name: "s", Children: [ { Id: 2, Name: "m", Children: [ { Id: 3, Name: "q", Children: [ { Id: 4, Name: "a", Children: [ { Id: 5, Name: "w", Children: [ { Id: 6, Name: "needed", Children: [], } ], } ], } ], } ], } ], }, ] I wanna return the item matches Id 6

提交回复
热议问题