I am new in JS and need some help. In this example: I have a List, in this list are "keywords" in an array.
I have found some links, but I don't know how to put this into my script right now..
find String of an Array that is in an array
Javascript: Search for an array in an array of arrays
-> So I want, when I search ["apple", "strawberry"] that the script outputs the most matched list.
This was my idea, I tried many things.. but nothing worked out like I was supposed to.
var groups = [
{name: 'fruits', words:["apple","strawberry", "banana"]},
{name: 'test', words:["asd","qwe"]}
];
var searchwords = ["apple", "strawberry"];
for(i = 0; i < groups.length; i++) {
console.log(groups[i]);
for(i = 0; i < searchwords.length; i++) {
console.log(searchwords[i]);
console.log('The most matching list is: ' + groups.name);
}
}
OUTPUT should be:
The best group is "fruits" group.
And I want a list (output), like that:
result = [2,0]
The "2" is for the List "fruits", because there are 2 words in it. The "0" is for the List "test", because there no matching words.
Thank you!