Why is this function returning undefined? It has a value inside the function, but once I try to assign it to a new variable, it comes back as undefined.
function getLookupDefault(lookupModel) {
Object.keys(lookupModel.LookupValues).forEach(function (key) {
if (lookupModel.LookupValues[key].IsDefault == true) {
test = lookupModel.LookupValues[key].Name;
console.log("test: " + test);
return test;
}
})
};
var tst = getLookupDefault(model.LookupValuesDelimiter);
console.log("tst: " + tst);
Edit: Thank you. Coming from c#, this was not obvious to me. I have edited the code to this and it works correctly.
function getLookupDefault(lookupModel) {
for (var key in Object.keys(lookupModel.LookupValues)) {
if (lookupModel.LookupValues[key].IsDefault == true) {
test = lookupModel.LookupValues[key].Name;
console.log("test: " + test);
return test;
}
}
}