I did some research on stackoverflow, but I didn't find an answer to my problem, and I still cannot comment, so I can't ask.
I have an asynchronous method from which I need to get a return value to a method which calls it:
somefunc(data) {
var x = filterSwear(data);
// do sth...
// ...
}
function filterSwear(msg) {
var xx;
$.get('/swearWords.csv', function(data) {
var swearWords = data.split(',');
for(var i = 0; i < swearWords.length; i++) {
var subs = "***";
var x = "".concat("\b" + swearWords[i] + "\b"); // !
var reg = new RegExp(x, "gi");
xx = msg.replace(reg, subs);
}
//console.log(xx);
});
//console.log(xx);
return xx;
}
The problem is to get the data back to the first function. Or should I maybe continue with the original function in there, where I have the data?
P.S. I found a partial answer to my question here