Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda