0

I'm trying to test if an array contains a specific substring, but I can only get a match if the substring = array value

This is my test code:

var test = ["something", "my-name", "name-test"];
if (test.includes('name')) {
  console.log(test);
}

I've also tried with indexOf('navn') !== -1 and jQuery inArray.

However, no matter what I try, it only works if I my substring == array value, but I need 'name' to be 'true' when array value is e.g. 'my-name' or 'name-test'.

It seems so simple, yet I can't get it to work.

halfer
  • 19,471
  • 17
  • 87
  • 173
Dyvel
  • 695
  • 1
  • 7
  • 17

0 Answers0