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

93
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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