I am trying to iterate over an array in a forEach loop, reading out values. Actually, nothing unusual.
I’m trying to access the array[index+1] element in the loop and read out the name property (Second to last line).
In my Browser Console, I got the error:
Error loading workflow TypeError: Cannot read properties of undefined (reading ‘name’)
This is what the array looks like:
{
"nodes": [
{
"id": "Http Request",
"name": "Http Request"
},
{
"id": "Initialize input",
"name": "Initialize input"
}
],
"links": [
{
"source": "Http Request",
"target": "Initialize input",
"value": 59
}
]
}
And here is the code:
chartData.nodes.forEach((node: any, index: any, array: any) => {
if(index === 2) {
chartData.links.push({
source: this.splitAndJoin(actionRootNode),
target: this.splitAndJoin(node.name),
value: 0
});
}
else if(index > 2 && index < chartData.nodes.length) {
chartData.links.push({
source: this.splitAndJoin(node.name),
target: this.splitAndJoin(array[index+1].name),
value: 0
})
}
})
The goal is to create Data (nodes and links) for a D3.JS Chart.

