So I have a list a that contain the string "ab" and another list b that contain a list that contain the string "ab". So it look something like this:
var a = ["ab"]
var b = [["ab"]]
How can I check if a is in b. I have try using b.includes(a) that result in a false and I also have try b.indexOf(a) which also return false. The way that I currently use is this:
var flag = false
var a = ["ab"]
var b = [["ab"]]
b.forEach((i) => {
if (i.join("") == a.join("")) flag = true
})
console.log(flag)
Is there like a shorter way?
Thanks y’all.
>Solution :
Little trick for you. You can compare two array if you use toString() method.
const a = ["ab"];
const b = [["ab"]];
const result = b.some(p => p.toString().includes(a));
console.log(result);