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

113
Views
Is there a way to know alle the positions of a certain part of a string?

I'm looking for a way to know all the positions of a certain part of a string, so for example, if I have a let variable = "test" and I want to know the location of all the "t"s.

I tried using indexOf(), but it does only return the location of the first "t" and stops afterwards.

Is there a way to do this with all "t"s?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

let x = "test"
let y = []
for (let i = 0; i < x.length; i++){
   if (x[i] == "t") y.push(i)
}
console.log(y)

about 4 years ago · Juan Pablo Isaza Report

0

let variable = "test";
for (let i = 0; i < variable.length; i++){
    if (variable[i] === 't'){
        console.log(i);
    }
}

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!