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

167
Visualizações
Retrieve data from an array of objects in Google Script

i am trying to extract certain elements from the below array of objects called atstudentsarray and create a new array with objects. I have used the below map function but i can not get it to work.

var newAtStudentArray = atstudentsarray.map(i => {
    const newAtStudentObj = {}

    newAtStudentObj.last_name = i['records'].fields['Last Name']
   
  })

Below is an array called atstudentsarray

[{
    "records": [
        {
            "id": "rec02fiiNA",
            "createdTime": "2020-04-21T05:06:07.000Z",
            "fields": {
                "Last Name": "Lat",
                "Gender": "Male",
                "E-mail Address": "alath@bbc.lk",
                "Grade": "DP 2",
                "parent_id_2": [
                    "rec3TCndXH"
                 ]
         }

         {
            "id": "rec02fiiNA",
            "createdTime": "2020-04-21T05:06:07.000Z",
            "fields": {
                "Last Name": "Lat",
                "Gender": "Male",
                "E-mail Address": "alath@bbc.lk",
                "Grade": "DP 2",
                "parent_id_2": [
                    "rec3TCndXH"
                 ]
         }
             ]

}]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You must use "return" if you use "{}" brackets in your arrow function. Add "return newAtStudentObj;" at the end:

var newAtStudentArray = atstudentsarray.map(i => {
    const newAtStudentObj = {}

    newAtStudentObj.last_name = i['records'].fields['Last Name']
    return newAtStudentObj;
})
about 4 years ago · Juan Pablo Isaza Relatório

0

Your can try it like this:

var newAtStudentArray = atstudentsarray[0].records.map(i => ({
    last_name: i.fields['Last Name']
  }))

The reason why it didn't work for you is because atstudentsarray is not the array you should be doing map on but on records array.

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