Let me explain my issue. I have a foreach loop and a switch condition inside it. In every switch case, I have concat the results in to a global array.
var resultArray = [];
Panels.forEach(function (panel, index) {
switch( panel.CategoryId ){
case 'math':
resultArray = resultArray.concat(SOMEVALUE COMES FROM DB);
break;
case 'physics':
resultArray = resultArray.concat(SOMEVALUE COMES FROM DB);
break;
case 'zoology':
resultArray = resultArray.concat(SOMEVALUE COMES FROM DB);
break;
}
return resultArray;
})
But the output doesn't contain the values from all cases. I know its because of the asynchronous nature of nodejs. But how can we implement this function in to asynchronous?
Any ideas would be appreciable