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

211
Views
Check if sub object of javascript object contains a certain string

If I have a TypeScript Array of

things: Things[]

export type Party = {
  id: string;
  name: string;
};

export type Things = {
  party: Party;
  id: number;
  ...more stuff
};

how can I check if the things array has a Party with a certain name?

Something like included = things.includes(party.name.includes("Bob")) or included = things.some(party.name("Bob"))

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

0

You are almost there:

const included = things.some(thing => thing.party.name === "Bob")

You need to provide a function to some. That function will be called for every element and should return something that (when coerced to a boolean) indicates whether the element matches your criteria or not. In this case we pass a function that returns true if an element's party property has a name property that is equal to "Bob".

about 4 years ago · Juan Pablo Isaza Report

0

You could use .find

const included = !!things.find(thing => thing.party.name === 'Bob')

P.S !! before the statement makes included as a boolean

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!