node red - Javascript Nested Loop Pushing to Array -


i relatively new programming , having issues project working on.

msg.newcg2 = []; for(i=0;i<msg.newcg.length;i++){     for(j=0;j<msg.campaigngroup.length;i++){         if(msg.campaigngroup[j].col10 === msg.newcg[j]){             msg.grouptotals = msg.grouptotals + msg.campaigngroup[j].col11;     }     msg.newcg2.push(msg.newcg[i], msg.grouptotals)     } } 

basically, each 1 of "ids" (integers) in msg.newcg, want each id in msg.campaigngroup , sum totals listings same id, msg.campaigngroup.col11 - push id , totals new array - msg.newcg2.

when run code, first item sent through processes, grinds halt because of memory. assume because of error in code.

where did code go wrong? sure there better ways whole, curious went wrong.

there typo in second loop , push needs happen inside outer loop.

msg.newcg2 = []; for(i=0;i<msg.newcg.length;i++){     for(j=0;j<msg.campaigngroup.length;j++){         if(msg.campaigngroup[j].col10 === msg.newcg[i]){             msg.grouptotals = msg.grouptotals + msg.campaigngroup[j].col11;         }     }     msg.newcg2.push(msg.newcg[i], msg.grouptotals)  } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -