I'm struggling to get one of my JavaScript functions return its value. Please observe following code:
function GW2API_getEventInfo(p_eventid) {
console.log("Getting EventInfo for event " + p_eventid);
$.each(arrEvents, function(i, eventItem) {
$.each(eventItem, function(j, eventInfo) {
if (eventInfo.event_id == p_eventid) {
console.log(GW2API_getEventName(p_eventid) + " - " + eventInfo.state);
return {
'name': GW2API_getEventName(p_eventid),
'state': eventInfo.state
};
}
});
});
}
Now I would like to return an object with two properties: 'name' and 'state'. However, no matter what I add underneath the console.log, my function isn't returning anything (although data is found, hence the console is logging).
currEvent = GW2API_getEventInfo(GW2API_events_ShadowBehemoth[i]);
alert(currEvent) --> yields "undefined"
.each()instead of a standardfor()loop. That's the root of the problem here.