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

114
Vistas
How to filter object array and return only 2 of 4 properties and formated?

I receive from API the following object array:

{id: 0, color: 'Red', code:'AAA'}
{id: 1, color: 'Blue', code:'BBB'}
{id: 2, color: 'Orange', code:'CCC'}
{id: 3, color: 'Black', code:'DDD'}

how can I return it for another array but only if id is > 1 and like this:

const arrayFiltered = { 'Orange#CCC', 'Black#DDD' }

I need convert it in a string array and concatenate 2 atributes...

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your desired output is invalid. arrayFiltered will be an array not an object, its output would be like ['Orange#CCC', 'Black#DDD']

const arrayFiltered = arrayInput.filter(c => c.id > 1).map(c => c.color + c.code);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Assuming given array is givenArr

const givenArr = [
  {id: 0, color: 'Red', code:'AAA'},
  {id: 1, color: 'Blue', code:'BBB'},
  {id: 2, color: 'Orange', code:'CCC'},
  {id: 3, color: 'Black', code:'DDD'}
]

result = givenArr.filter((val) => val.id > 1).map((item) => `${item.color}#${item.code}`)

console.log(result)
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