Home > front end >  Want to put the outer array of selected and chlidren selected attributes are changed to false the re
Want to put the outer array of selected and chlidren selected attributes are changed to false the re

Time:04-20

Let newArr=[
{
Name: "2020 collection,"
Selected: true,
Children:
{
Id: 1,
Selected: true,
Name: "summer",
},
{
Id: 2,
Selected: true,
Name: "autumn",
}
]
}
]

CodePudding user response:

 
The function changeSelected (source) {
Source. The forEach (item=& gt; {
Item. The selected & amp; & (item. Selected=false)
Item. Children & amp; & ChangeSelected (item. Children)
})
}

ChangeSelected (newArr)

The console. The log (newArr)


If don't want to change newArr directly, it will first newArr deep copy a perform again
  • Related