I have the following 2d array:
const sample = [
['Name 1', 'Name 2, Name 3', 'Name 4'],
['', 'Name 5', 'Name 6, Name 7'],
['Name 8, Name 9', 'Name 10', '']
]
As you can see, some strings have more than one name (separated by a comma)
I have the following function that return true if input name has an index of 0 or 1 otherwise it returns false:
function indexIsZeroOrOne(arr, name) {
for (const row of arr) {
const i = row.indexOf(name)
if (i === 0 || i === 1) {
return true
}
}
return false
}
It works with strings that have a single name but not with those with multiple names.
How to modify this so that calling, for example: console.log(indexIsZeroOrOne(sample, 'Name 2') would return true?