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

209
Views
How do I add lists from objects to other objects (connected with id)

I have two JSON files and I need to get the program to log the names from the other and under each name I need to log a list of titles that belong to that name from another JSON file. They are connected with an id but on the other file the correct id is named "id" and on the other, it's "userId" (and there is a key-id also but refers to something else.

The data is from here: https://jsonplaceholder.typicode.com/posts and here https://jsonplaceholder.typicode.com/users

What I need is something like this:

name1<br>
-title1<br>
-title2<br>
-title3<br>
-title4<br>

name2<br>
-title5 <br>
-title6<br>
-title7<br>
-title8
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One solution is to use a nested for-loop:

for (let user of users) {
  console.log(user.name);
  for (let title of titles) {
    if (user.id == title.userId) {
      console.log(`\t- ${title.title}`);
    }
  }
}

Results in something like:

Leanne Graham
    - sunt aut facere repellat provident occaecati excepturi optio reprehenderit
    - qui est esse
    - ea molestias quasi exercitationem repellat qui ipsa sit aut
    - eum et est occaecati
    - nesciunt quas odio
    # ...
Ervin Howell
    - et ea vero quia laudantium autem
    - in quibusdam tempore odit est dolorem
    # ...

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!