When I use the getTotal.getValues() function to make a server call that returns values like "one", "two", "three" up to "nine", I am able to print them using console.log(res). However, I am facing an issue where I cannot push these returned values into the variable v that I created inside the runTest function. The problem is that when I run the code, console.log(r) does not display anything because the return v is empty. Any suggestions on how to resolve this?
var test = [1,2,3,4,5,6,7,8,9];
function runTest(val) {
var v = [];
val.forEach(function(t) {
getTotal.getValues(t).then(function(res) {
//console.log(res);
v.push(res);
});
});
return v;
}
runTest(test).forEach(function(r) {
console.log(r);
});