This might be more to do with my lack of understanding some JS basics however it's in ethereum/web3 context so here it goes.
I have a public array posts in my contract and a global variable in JS of the same name.
Using truffle/pudding framework on the frontend I am then trying to iterate through the array doing something like this:
length = 3;
posts = new Array(length);
for(i = 0; i < length; i++ ){
social.posts.call(i).then(function(v){
posts[i] = v;
});
}
However by debugging I found out that the anonymous function gets executed only once and with i equal to 3. posts[3] gets set and nothing else. I must be doing something silly here. Please help.
Edit: So I understand now that the problem is because of the promises but is there another way to easily retrieve array values from the contract? Pudding was meant to help with this.