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

299
Views
How to return the data not [object object] JS

I am tring to print just the the lists and tasks i get an [object object]

here is my code :

const users = {
  user1: {
    lists: [
      {
        id: 0,
        name: "Work",
        tasks: [
          {
            id: 0,
            task: "task to do",
          },
          {
            id: 1,
            task: "task to do",
          },
        ],
      },
      {
        id: 1,
        name: "Holiday",
        tasks: [
          {
            id: 0,
            task: "task to do",
          },
          {
            id: 1,
            task: "task to do",
          },
        ],
      },
      {
        id: 3,
        name: "New List",
        tasks: [],
      },
    ],
  },
};

and this what i tried:

$.each(users, function (key, value) {
  const keys = key;
  console.log(keys)
  let test = users[key];
  console.log(test)
  $.each(test, function (key, value) {
    value;
    console.log(value)
  $.each(value, function (key, value) {
    value.name
    document.write(value.name)
    document.write(value.tasks)
  })
  });
});

this what it returns:

Work[object Object],[object Object]Holiday[object Object],[object Object]New List

my questions:

  • how i return the list alone , and tasks alone?
  • is there any problem with my data structure?

i am just beginner

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First, I will ask that you try not to use jQuery ($) for everything when it's not needed.

Secondly, you have a variable called users, which I would think should be an array, but you have it down as a keyed object. Might be worth looking into.

Anyway, I'll try to help you with the "list alone" and "tasks alone"-stuff!

const users={user1:{lists:[{id:0,name:"Work",tasks:[{id:0,task:"task to do"},{id:1,task:"task to do"}]},{id:1,name:"Holiday",tasks:[{id:0,task:"task to do"},{id:1,task:"task to do"}]},{id:3,name:"New List",tasks:[]}]}}

const allLists = []


// id is "user1", user is the user-object.
for(const [id, user] of Object.entries(users)) {
  const lists = user.lists
  for(const list of lists) {
    allLists.push(list)
  }
}


console.log(`ALL LISTS: ${allLists}`) // Lots of "[object Object]"
console.log(`ALL LISTS: ${JSON.stringify(allLists)}`) // This one works

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!