for(var i = 0; i < BoardMessages.length;i++){
(function(j){
console.log("Loading message %d".green, j);
htmlMessageboardString += MessageToHTMLString(BoardMessages[j]);
})(i);
}
That should work; however, you should never create a function in a loop. Therefore,
for(var i = 0; i < BoardMessages.length;i++){
composeMessage(BoardMessages[i]);
}
function composeMessage(message){
console.log("Loading message %d".green, message);
htmlMessageboardString += MessageToHTMLString(message);
}