I have a set of values (groups) in a comma delimited string and would like to check if any of those values match any array items (reqRights) and return true or false, but is returns undefined error.
const reqRights = ["18900253","3217840","1053"];
const groups = "3217635,18272308,1053,3217633,18900253,3217698,3217699,3217840,10162510";
function checker(value) {
var groups = groups.split(",");
console.log(groups);
return groups.every(function(v) {
return value.indexOf(v) !== -1;
});
}
arr = reqRights.filter(checker);
console.log(arr);
js engine SpiderMonkey 1.8, does not support .includes and some methods
groups.split(",");every single index just makes your loop so much slower. Do it outside so you are not constantly splitting the string up.var groups = groups.splitYou can not reuse the same variable. That is your error. Rename one.