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

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

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