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

125
Visualizações
Return all nested objects with specific keys

I have an array of objects in Javascript:

[
{a: 1, b: 2, c: 4},
{d: 10, a: 9, r: 2},
{c: 5, e: 2, j: 41}
]

I would like to return an array of all the objects that have the key name c by using the key name for the lookup.

What is the best way to accomplish this?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

.filter + in operator

var arr = [
    {a: 1, b: 2, c: 4},
    {d: 10, a: 9, r: 2},
    {c: 5, e: 2, j: 41}
];
var result = arr.filter((x) => 'c' in x);
console.log(result)
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use filter method and hasOwnProperty

const arr = [{a: 1, b: 2, c: 4},{d: 10, a: 9, r: 2},{c: 5, e: 2, j: 41}];
const myArray = array.filter(e => e.hasOwnProperty('c'))
about 4 years ago · Juan Pablo Isaza Relatório

0

use filter(), and maybe hasOwnProperty() or another way to check if the property is present on the object.

const myarray = [
    { a: 1, b: 2, c: 4 },
    { d: 10, a: 9, r: 2 },
    { c: 5, e: 2, j: 41 }
];

const processedarray = myarray.filter( item => item.hasOwnProperty( 'c' ) );

console.log( processedarray );

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