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

131
Vistas
How to retrieve items id from an array of object and put it in an array using javascript?

below is an array of object

const arr_obj = [
    {
        'id': 1,
        'items': [
            {
                'id':'1',
                'data': {
                    'id': 3,
                }
             },
             {
                 'id': '2',
                 'data': {
                     'id': 4,
                  }
              }
          ]
      },

      {
          'id': 2,
          'items': [
              {
                  'id':'3',
                  'data': {
                      'id': 5,
                  }
              },
          ]
      },
  ]

I want to retrieve the id property of items array and put it an array so the expected output is ['1','2','3']

could someone help me with this. thanks.

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

0

arr_obj.map(obj=>obj.items.map(item=>item.id)).flat()
  • .map loops over every item in an array and runs a transformation function on them, generating a new array.

  • .flat flattens a multi-dimensional array into a 1d array

I'd suggest looking into some of the other array methods, as they are very useful.


You could even improve this slightly with flatMap:

arr_obj.flatMap(obj=>obj.items.map(item=>item.id))
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