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

253
Views
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 answers
Answer question

0

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

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 Report

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 Report
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!