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

225
Visualizações
How do I find the "string number" of a given string, in an array?

I have the following array of strings:

array = ["fox jumps", "snail slides", "airplane flies"];

I'm trying to find the string in the array containing "airplane", and return the string number in the array.

I have the following code so far:

var array = ["fox jumps", "snail slides", "airplane flies"];
var el = array.find(a =>a.includes("airplane"));
console.log(el)

...which finds the string "airplane flies"

From this point, how do I return the string number? in this example, it should be "3"

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

0

findIndex almost does what you want, but note that arrays in JS are zero-based, and since you want a one-based result (you want to return 3 for the third element in the array, not 2), you need to add one:

var el = array.findIndex(a =>a.includes("airplane")) + 1;
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