Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda