Attached below is my JSON:
"mainSteps": [
{
"id": "9b3b64b4-d8a5-46d5-b464-066dc5c45dc3",
"name": "Main Step 1",
"steps": [
{
"name": "sub step 1.1"
},
{
"name": "sub step 1.2"
}
]
},
{
"name": "Main step 2"
"steps": [
{
"name": "sub step 2.1"
},
{
"name": "sub step 2.2"
}
],
},
{
"name": "Main Step 3",
"steps": [
{
"name": "sub step 3.1"
},
{
"name": "sub step 3.2"
}
],
}
]
I am looking for the desired output format like: [Main Step 1, sub step 1.1 , sub step 1.2], [Main Step 2, sub step 2.1 , sub step 2.2], [Main Step 3, sub step 3.1 , sub step 3.2]. I have spent the entire day trying to achieve this output but keep getting different formats such as [[Main Step 1, Main Step 2, Main Step 3, sub step 1.1, sub step 1.2....]. Despite trying various methods, I cannot seem to obtain the exact output as mentioned above. Can someone provide me with some clarification?
var dataProcess = {
parentProcess:[],
subProcess:[]
};
var steps = mainData.steps; // Steps containing the full JSON data
var proc = [];
$scope.getSteps = function(steps) {
for (var i=0; i < steps.length; i++) {
dataProcess.parentProcess.push(steps[i].name);
for(var j=i; j < steps[i].steps.length; j++){
dataProcess.subProcess.push(steps[i].steps[j].name);
}
}
This is one of the methods I have tried so far.