Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
How to use string.include(substring) to test presence

Suppose there are five words (substring) cat, dog, elephant, tiger, lion and there is a sentence string -- > "We have one cat in our home". Now i need to see which of the substring is present in the string.

So how can we use string.include(substring) to check if any of the substring in present in string and if true which substring is it.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can store the words to find in an array and use Array.filter to filter out the items that aren't included in the string.

const wordsToFind = ['cat', 'dog', 'elephant', 'tiger', 'lion']

const string = "We have one cat in our home";

const includedWords = wordsToFind.filter(e => string.includes(e))
const doesInclude = includedWords.length != 0;

console.log('Does include? ', doesInclude)
console.log('Included words: ', includedWords)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda