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

254
Vistas
extract only index with the value of "date" from a JSON file with javascript

I am accessing a JSON file with nodejs api request.

the file file has 1000's of data.

var data = fileData[0].data has the "date" values in multiple objects. The objects have two values "date" and "value". I just want to print the "date" values of the whole data variable.

"idNumber": "98745973459479574935794577345",
    "data": [
        {
            "date": "2001-09-12T08:37:09.009Z",
            "value": 307479
        },
        {
            "date": "2001-09-12T08:36:53.919Z",
            "value": 307478
        },
        {
            "date": "2001-09-12T08:36:38.809Z",
            "value": 307477
        },

There are thousands of these objects within the array. I just want to print all the "date". I tried console.log(data[0]) but it would print the first value and it will also include the "value" which I don't want.

is it possible to print every index with the keyword of "date"? If so, how?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

data.forEach(item=>{
console.log(item.date)
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to iterate whole array in order to get the date value.

You can use for loop, while loop, foreach etc, to iterate.

For Each Loop:

let data = [
        {
            "date": "2001-09-12T08:37:09.009Z",
            "value": 307479
        },
        {
            "date": "2001-09-12T08:36:53.919Z",
            "value": 307478
        },
        {
            "date": "2001-09-12T08:36:38.809Z",
            "value": 307477
        },
]

data.forEach(i => {
    console.log(i.date)
})

For Loop:

    let data = [
            {
                "date": "2001-09-12T08:37:09.009Z",
                "value": 307479
            },
            {
                "date": "2001-09-12T08:36:53.919Z",
                "value": 307478
            },
            {
                "date": "2001-09-12T08:36:38.809Z",
                "value": 307477
            },
    ]

    
    for(let i = 0; i < data.length; i++){
        console.log(data[i].date)
    }

about 4 years ago · Juan Pablo Isaza Denunciar

0

Map seems to be a good method for you

NOTE I name the outer object obj so to get the data I use obj.data

const obj = {
  "idNumber": "98745973459479574935794577345",
  "data": [{
      "date": "2001-09-12T08:37:09.009Z",
      "value": 307479
    },
    {
      "date": "2001-09-12T08:36:53.919Z",
      "value": 307478
    },
    {
      "date": "2001-09-12T08:36:38.809Z",
      "value": 307477
    }
  ]
}
console.log(obj.data.map(({date}) => date).join(','))

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