I know i should know how to do this but some how it escapes me. I need to exit the loop here once I have a match. Why does this not work?
ubot.registry.queue.each(function (dj, idx) {
console.log(idx);
var user = ubot.registry.users.get(dj.userid);
console.log(user.name);
console.log(rm_user)
if(user.name == rm_user) {
console.log(dj.userid);
return; // not exiting loop here
/*
if(!ubot.dj_timeout) {
ubot.remUserFromQueue(user);
return true;
} else {
console.log(ubot.dj_timout);
}
*/
}
});
Here’s a generic solution since you haven’t given us specifics on the code you’re running.
It doesn’t break the loop. Instead it prevents the code inside the function from running once a flag is set.
You’re returning
undefined, but functions always returnundefinedunless a specific return value is provided. So by doingreturn;you’re not doing anything different than the function would do anyway.