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

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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