initialize() {
var elements = [];
for (let i = 1; i <= 4; i++) {
let node = { name: `Node ${i}` };
elements.push({ [`node${i}`]: node });
if (i < 4) {
let edge = { source: `node${i}`, target: `node${i+1}` };
elements.push({ [`edge${i}`]: edge });
}
}
return { nodes: Object.assign({}, ...elements), edges: Object.assign({}, ...elements) }
}
Is there a way to loop through and create the same setup without manually writing each node and edge? Any suggestions would be helpful.