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

89
Vistas
How to array after object in Nodejs

I have array but i need to join object after array

my array

const users = [
      {name: "Joe", age: 22},
      {name: "Kevin", age: 24},
      {name: "Peter", age: 21}
    ]

my object

{ street: true }

result i need

[
      {name: "Joe", age: 22},
      {name: "Kevin", age: 24},
      {name: "Peter", age: 21}
    ], { street: true }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

If you want to join then up like an array you can do

const newArray = [users, { street: true }]

Otherwise if you want to join them up as a new object do

const newObject = {
  residents: users,
  info: { 
    street: true
  }
}

like @AT-martins suggested

about 4 years ago · Juan Pablo Isaza Denunciar

0

so you need an object with 2 properties, one could be called "residents" and the other "info", the structure would look like this:

{
 residents: [
      {name: "Joe", age: 22},
      {name: "Kevin", age: 24},
      {name: "Peter", age: 21}
  ],
  info: { 
    street: true
  }
}

I think this is the easiest way to have your array and your object in one single data structure.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Simply use push() for this. So you have this array:

const users = [
      {name: "Joe", age: 22},
      {name: "Kevin", age: 24},
      {name: "Peter", age: 21}
    ]

And you want to attach this:

const anotherObj = { street: true };

Then you can use this:

const users = [
      {name: "Joe", age: 22},
      {name: "Kevin", age: 24},
      {name: "Peter", age: 21}
    ];
const anotherObj = { street: true };
users.push(anotherObj);

This will do the job! But, the above is the solution if you want that object to go inside the array. If you want to make a new array, you can do this:

const arr = [users, anotherObj]

This will make a new array with the users array in index 0 and the obj at index 1

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