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

156
Views
Find matched string in an object that contains mutiple arrays

I have an object that contains multiple arrays of strings, like

const object = {
    "arrayA": [
        "A1",
        "A2"
    ]
    "arrayB": [
        "B1",
        "B2"
    ]
    ...
}

How can I use Javascript function or lodash to find if a given string exists in the object? Thanks

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  • Using Object#values, get the list of arrays
  • Using Array#some, iterate over this list to check if any array has the string using Array#includes

const checkForString = (obj = {}, str) =>
  Object.values(obj).some(arr => arr.includes(str));

const object = { "arrayA": [ "A1", "A2" ], "arrayB": [ "B1", "B2" ] };

console.log( checkForString(object, "A1") );
console.log( checkForString(object, "B1") );
console.log( checkForString(object, "C1") );

about 4 years ago · Santiago Trujillo 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!