As you can see in below code. I’m trying to check whether mergeUserArray
value is present in winArray
or not. But I’m not able to achieve it.
Because I want, if any other number is in mergeUserArray
it should match if three number combination present in it. Like 789 is present in 7189.
I tried regular expression too but it also didn’t work.
let regxWinArray = /(123)|(456)|(789)/g;
let winArray = [123,456,789];
// let mergeUserArray = [789]; --Value matched
let mergeUserArray = [7189]; // Value didn't match
if(winArray.includes(Number(mergeUserArray))){
console.log("Number matched");
}
else {
console.log("Number not matched");
}
3
Answers
Use global regex character match and check whether number of found characters match:
If the order of characters should match:
If we need all values in
mergeUserArray
matched: