I've got this massive nested for loop with a few if and else statements in nodeJs. The output of all of this is just string which is combined from different values out of JSon object. What I want to do is rewrite it in more efficient way as JSlint plugin for sublime is complaining about complexity of it:
var instancesList = '';
ec2.describeInstances(params,function(err, data) {
if (err){
console.log(err, err.stack);
} else {
for (var i in data.Reservations){
for (var j in data.Reservations[i].Instances[0].Tags){
if(data.Reservations[i].Instances[0].Tags[j].Key == 'Name'){
instancesList+= 'Name: ' + data.Reservations[i].Instances[0].Tags[j].Value +
' id: ' +data.Reservations[i].Instances[0].InstanceId +
' Status: ' + data.Reservations[i].Instances[0].State.Name +'\n';
}
}
}
}
console.log(instancesList);
Any help, ideas or a link on how to deal with these kind of situations would be greatly appreciated.