Re: [nodejs] variable scope in for loops

2015-05-23 Thread Prabhash Rathore
Hi Marc, Looks like you are overwriting the objects with the next subsequent values and hence you are left with the last value in your object. Make sure you copy values in new object for each iteration instead of just overwriting the same object. On Sat, May 23, 2015 at 4:19 PM, Marc Phillips wro

Re: [nodejs] variable scope in for loops

2015-05-23 Thread Ryan Schmidt
On May 23, 2015, at 6:19 PM, Marc Phillips wrote: > I'm building up an object (or trying to) iterating though a json object and > gathering info based various rest calls: > > var generate = {}; > for(var protocol in buildout.protocols){ > for(var item in buildout

Re: [nodejs] variable scope in for loops

2015-05-23 Thread John Shaver
Hey Marc, Generate is not an array, but an object (which can be used as a key/value store). There are a couple of possible problems, assigning to the object instead of a property on the object, or assigning everything with the same key. Unfortunately, without more code (like the code that assig

[nodejs] variable scope in for loops

2015-05-23 Thread Marc Phillips
I'm building up an object (or trying to) iterating though a json object and gathering info based various rest calls: var generate = {}; for(var protocol in buildout.protocols){ for(var item in buildout.protocols[protocol]){ switch (item) {