Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!