T
T
T3R3AND2020-09-28 10:47:38
JavaScript
T3R3AND, 2020-09-28 10:47:38

Having words from a string in an array?

I have an array and a string:

the code
var arr = ['я', 'тест', 'привет'];
var str = 'Привет, я пока чтт ещё здесь.';


How can I check if there are matches and perform a definition for each match? actions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-09-28
@T3R3AND

arr.forEach(w => {
  if ( str.indexOf(w) !== -1 ) { ... } // В строке есть слово из массива
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question