Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda