Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

328
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda