I have an Array like below (code session 2) . And I want add id : random into {child Obj} like this:
{
name : "Peter",
age : "18",
profession : "nurse",
id : String(Math.random())
children : [],
}
But it have 2 cases : value of key children may be [ ] or [ length !== 0 ]. I want to loop infinity the parent Array and add id for all.
Note : value of key children inside every {childObj} maybe an Array look like Parent Array. My final target is set id for all element from response API look like the template array
Thank you too much and sorry about my English if it make you feel complex
[{
name : "Peter",
age : "18",
profession : "nurse",
children : []
}
{
name: "Jack",
age: "98" ,
profession: "doctor",
children: [ {
name : "Peter",
age : "18",
profession : "nurse",
children : []
},
{
name: "Varun",
age: "80"
profession: "scientist"
children: [
{
name: "Ishan"
age: "62",
profession: "teacher
children: [{....
.....
.....[{
name: "Rahul",
age: "23",
profession: "engineer"
children: [{
.....