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

300
Views
How best to search a Javascript array for partial matches?

I'm very new to Javascript and I expect there is a simple answer, but how can you search a Javascript array for a partial match?

So if I have an array such as:

const fruits = ["Banana", "Orange", "Apple", "Mango"];

I know I can easily check if the array contains something using:

fruits.includes("Mango");

But what if I want to know whether an array contains a value that partially matches a certain sequence of characters?

For example, if I want to know if the above array includes an entry that has the string "Man" in it.

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

0

You can use filter if you want to find multiple objects might match, or find if you only want one, or if you just want to know if it exists at all use some

const fruits = ["Banana", "Orange", "Apple", "Mango"];

const fruitsWithMan = fruits.filter(x => x.includes("Man"))
console.log(fruitsWithMan); // returns array

const oneFruitWithMan = fruits.find(x => x.includes("Man"))
console.log(oneFruitWithMan); // returns single item

const hasFruitWithMan = fruits.some(x => x.includes("Man"));
console.log(hasFruitWithMan); // return boolean

about 4 years ago · Juan Pablo Isaza Report

0

You could filter the array this way :

const fruits = ["Banana", "Orange", "Apple", "Mango"];

console.log(fruits.filter(fruit => fruit.includes("Man")));

about 4 years ago · Juan Pablo Isaza Report

0

["Banana", "Orange", "Apple", "Mango"].some(fruit => fruit.includes("Man"));
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!