Want to update a value in multi nested array

Viewed 271

I want to update a value in the nested array. This value changed in all child and sub-child like in the tree view when we select the parent then all its children are selected automatically. Thisis how my tree structure.

This is my nested array data.
I want to update "Ischecked" value to "Yes" for all nested array

1 Answers

Go to the specific index, map the arrays and res-assign the values. Say at index 6:

array[6].children = array[6].children.map(child => ({...child, isChecked: 'Yes'}))

If they're multiple arrays, you can do a for...loop or map on the main array too:

  arrays.map(arr => { // You can use a for...loop here
    array.children = array[6].children.map(child => ({...child, isChecked: 'Yes'}))
    return arr;
  })
Related