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

139
Views
search in array in arry of objects by single character

How to search in an array inside the array of the object by one single character

    const arr = [{ x: 1, tags: ["tag1", "taf", "ee", "xx"] },{ x: 3, tags: ["ta", "e", "xx"] }];

const fResult = arr.filter((res) => res.tags().includes("tag1"));

this will return the value if we input a full tag1 word, not just "t" or "ta"

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

0

If you want to match that the value starts with it then you want to use some()

const filterIt = (arr, text) => arr.filter(
  (res) =>
  res.tags.some(
    val => val.startsWith(text)
  )
);

const arr = [{
  x: 1,
  tags: ["tag1", "taf", "ee", "xx"]
}, {
  x: 3,
  tags: ["ta", "e", "xx"]
}];

console.log("t", filterIt(arr, "t"));
console.log("ta", filterIt(arr, "ta"));
console.log("tag", filterIt(arr, "tag"));

about 4 years ago · Juan Pablo Isaza Report

0

finally figured out this simple solution

by converting the array of tags to string, then checking by including is solve everything

    const arr = [{ x: 1, tags: ["tag1", "taf", "ee", "xx"] },{ x: 3, tags: ["ta", "e", "xx"] }];

here is the solution const fResult = arr.filter((res) => res.tags.toString().includes("tag1"));

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!