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

200
Visualizações
Is the empty string a subtring of all strings?

I've been designing a search bar function that removes results that do not include the value of the user input. So far it's been successful, but when the user enters an empty string, I want it to return back to default and reverse all of the hidden posts. And while it does work, I wanted to ask the question if all strings contain a substring "" which is empty as it would help my understanding.

Here is what I mean:

let strArray = ['Hello', 'w', '324551', ''];

for (var i=0; i<strArray.length; i++) {
    console.log(strArray[i].indexOf("") !== -1);
}

Output: 
    True
    True
    True
    True

This may be a simple question to answer for some, but I'd just like clarification to reason my work.

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

0

Yes it is. From the spec:

  1. If searchValue is the empty String and fromIndex ≤ len, return fromIndex.

Where fromIndex is almost always 0. (It will only not be 0 if you pass a second optional parameter to indexOf)

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