var data = [
{
"something": "something",
"stages": [{
"node": {"name": "test0"},
"status": {"name": "test"},
"time": {"name": "test"}
},{
"node": {"name": "test1"},
"status": {"name": "test"},
"time": {"name": "test"}
}]
}
];
nodeList = []
data.forEach(obj =>
obj.stages.forEach(stage => if (nodeList.indexOf(stage.node.name) > -1) {
nodeList.push({stage.node.name})
);
I am trying to add the name to a list if that name does not already exist in the list. The above is not working.
in operatorgets you indexes. Useof operatorofthis.job[0].stage[i].for(... in ...)iterates through the keys in an object. In your exampleiis a string, not a stage.for (node in this.job[0].stage[i]) { console.log(node.name) }. i is a property name, not a reference. You might also needfunction nodeName() { ... }.