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

161
Visualizações
Using array of object create a new array that contains all the objects from the original array of object that have a numerical value greater than 15

help please, i have this array of object and must to create a new array that contains all the objects from the original array of object that have a numerical value greater than 15. how can i do this ? which method a must to use ?

const names = [
  { name: 'Anna' },
  { num: 27 },
  { name: 'Valeria', age: 20},
  { secondname: 'Wilson' },
  { age: 12, name: 'Max' },
  { weight:'50kg', height: '172cm', name: 'Nick' }
] 

i try to use filter,but it should see any field that has a number value not just age or num

const number = arr.filter(a => a.num || a.age > 15);
console.log(number); 
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

If you like to get only numbers, you chould check the values of the object with Array#some and typeof operator.

const
    names = [{ name: 'Anna' }, { num: 27 }, { name: 'Valeria', age: 20 }, { secondname: 'Wilson' }, { age: 12, name: 'Max' }, { weight: '50kg', height: '172cm', name: 'Nick' }],
    result = names.filter(o => Object
        .values(o)
        .some(v => typeof v === 'number' && v > 15)
    );

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

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