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

75
Views
using data structures in chartjs

I am trying to load data in my chartjs and it looks something like this:

const data = [
{_id:1,contact:[{name:"Jane Doe",PhoneNumber:0234567}],Group:"groupName"},
{_id:2,contact:[{name:"Jane Doe",PhoneNumber:0234567}],Group:"groupName1"},
{_id:3,contact:[{name:"John Doe",PhoneNumber:0234567}],Group:"groupName1"}
]

I want my chart to look like this

[name:...,phoneNumber:...Group:....]

How do I achieve this

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

0

You can use map function for that.

Try this

const data = [
    {
        _id: 1,
        contact: [{ name: "Jane Doe", PhoneNumber: 0234567 }],
        Group: "groupName"
    },
    {
        _id: 2,
        contact: [{ name: "Jane Doe", PhoneNumber: 0234567 }],
        Group: "groupName1"
    },
    {
        _id: 3,
        contact: [{ name: "John Doe", PhoneNumber: 0234567 }],
        Group: "groupName1"
    }
];

data.map(item => {
    return {
        name: item.contact[0].name,
        phoneNumber: item.contact[0].PhoneNumber,
        Group: item.Group
    };
});

Output

[
    {
        "name": "Jane Doe",
        "phoneNumber": 80247,
        "Group": "groupName"
    },
    {
        "name": "Jane Doe",
        "phoneNumber": 80247,
        "Group": "groupName1"
    },
    {
        "name": "John Doe",
        "phoneNumber": 80247,
        "Group": "groupName1"
    }
]
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!