Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda