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

202
Views
How t convert JavaScript objects into array of objects?

I want to convert objects as shown here to array of objects:

My code:

entireObject =   {
        "++255 638-1527": {
            "email": "info@gmail.com",
            "phoneNumber": "++255 638-1527"
        },
        "+255 532-1587": {
            "email": "uihy@gmail.com",
            "phoneNumber": "+255 532-1587"
        },
        "+255 613-1587": {
            "email": "klch@gmail.com",
            "phoneNumber": "+255 613-1587",
            "info": [
                {
                    "date": "2022-02-19",
                    "count": 1
                },
                {
                    "date": "2022-03-17",
                    "count": 9
                }]
       }
}

I want to convert this to array of objects so, the output should look like this:

entireObject =   [
        {
            "email": "info@gmail.com",
            "phoneNumber": "++255 638-1527"
        },
            "email": "uihy@gmail.com",
            "phoneNumber": "+255 532-1587"
        },
        {
            "email": "klch@gmail.com",
            "phoneNumber": "+255 613-1587",
            "info": [
                {
                    "date": "2022-02-19",
                    "count": 1
                },
                {
                    "date": "2022-03-17",
                    "count": 9
                }]
            }
}

I need the data like this in order to render it in HTML, so How can I do this?

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

0

The desired result should end with ] in order to be a valid array, not }. All you need is Object.values() as in the following demo.

const entireObject =   {
        "++255 638-1527": {
            "email": "info@gmail.com",
            "phoneNumber": "++255 638-1527"
        },
        "+255 532-1587": {
            "email": "uihy@gmail.com",
            "phoneNumber": "+255 532-1587"
        },
        "+255 613-1587": {
            "email": "klch@gmail.com",
            "phoneNumber": "+255 613-1587",
            "info": [
                {
                    "date": "2022-02-19",
                    "count": 1
                },
                {
                    "date": "2022-03-17",
                    "count": 9
                }]
       }
};

const arr = Object.values( entireObject );

console.log( arr );

about 4 years ago · Juan Pablo Isaza Report

0

you could do something like this:

const myObject = {
  "++255 638-1527": {
    email: "info@gmail.com",
    phoneNumber: "++255 638-1527"
  },
  "+255 532-1587": {
    email: "uihy@gmail.com",
    phoneNumber: "+255 532-1587"
  },
  "+255 613-1587": {
    email: "klch@gmail.com",
    phoneNumber: "+255 613-1587",
    info: [{
        date: "2022-02-19",
        count: 1
      },
      {
        date: "2022-03-17",
        count: 9
      }
    ]
  }
};

let result = Object.values(myObject).map((item) => ({ ...item
}));
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Just wanted to point you in the right direction as a similar question was asked and perfectly answered. Here's the link: How to convert object containing Objects into array of objects N.B. please make sure to see the answer which is voted as the best answer.

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!