Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!