Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to check if a list exist inside another list

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading