I have this array nested in another array. I need the processId
within the processes
array.
I have this and it is not doing the job. I am missing some operator. Variables processIds
and processes
have the same data.
"statusIds" :[
],
"menuItems": [
{
"menuId": 64,
"processes": [
{
"processId": 117,
"otherids": [
8,
3
],
"other": []
}
],
"forms": []
},
{
"menuId": 605,
"processes": [],
"forms": []
}
],
for (let x = 0; x < menuItems.length; x++) {
let p=menuItems[x].processes
processIds.push(...p);
}
console.log(processIds)
for (let y = 0; y < processIds.length; y++) {
let p1=processIds[y]
processes.push(p1)
}
console.log(processes)
2
Answers
If you have the
menuItems
array assigned to the variablemenuItems
and you’re just trying to pull out the process ids:Changed to line :
let p1 = processIds[y].processId