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

326
Views
How to create an object of arrays in javascript

I have a collection in mongodb with a value o type array with 12 rows in it. See the screenshot: enter image description here

In my code make an axios request in the componentDidMount and successfully get the respone and values

async componentDidMount() {

    const {data: locations} = await axios.get('http://localhost:4000/try1');
    this.setState({locations})
    console.log(locations)

    // Use processCsvData helper to convert csv file into kepler.gl structure {fields, rows}
    const data = Processors.processCsvData(nycTrips);
    console.log(data)

    // Create dataset structure
    const dataset = {
      data,
      info: {
        // `info` property are optional, adding an `id` associate with this dataset makes it easier
        // to replace it later
        id: 'my_data'
      }
    };
    // addDataToMap action to inject dataset into kepler.gl instance
    this.props.dispatch(addDataToMap({datasets: dataset}));
}

The problem is I am getting the location object like shown in this screenshot:

enter image description here

but my required output is as shown below:

enter image description here

I need the required output to pass it to my mapping application so that the map markers can be generated.

Please advise how I can create an object in the required format.

Following is my simple get api:

app.get('/try1', (req, res) => {
    try1.find()
    .then(data => res.json(data))
})

Thanks in advance guys.

about 4 years ago · Juan Pablo Isaza
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!