-3
const scraper = require("table-scraper"); //scrape a html table
scraper
   .get("https://www.gkd.bayern.de/de/meteo/wind/isar/ammerseeboje-16601050/messwerte/tabelle") 
      //that is the list of wind values for each hour
   .then(function (tableData) {
      console.log(tableData[1]); //that is the table as an object
  })

console returns :

 [
    { Datum: '05.06.2021 21:00', 'Wind [m/s]': '5,7' },
    { Datum: '05.06.2021 20:00', 'Wind [m/s]': '5,4' },
....
]

tableData[1][0].Datum - ok defines the datum
but
tableData[1][0].'Wind [m/s]' - will return undefined...
How can I get the value of eg. 5,7?
Thanks

GeorgB
  • 17
  • 1
  • 7

3 Answers3

1

const tableData = [{
    Datum: '05.06.2021 21:00',
    'Wind [m/s]': '5,7'
  },
  {
    Datum: '05.06.2021 20:00',
    'Wind [m/s]': '5,4'
  }
]


console.log(tableData[0]['Wind [m/s]'])
Dassy Areg
  • 15
  • 8
-1

I'm not completely sure I understand the questions but if you're trying to return the value 5,7 I'm thinking you might need something like this:

const data = [{
    Datum: '05.06.2021 21:00',
    'Wind [m/s]': '5,7'
  },
  {
    Datum: '05.06.2021 20:00',
    'Wind [m/s]': '5,4'
  }
]

console.log(data[0][`Wind [m/s]`])
Ross Moody
  • 773
  • 3
  • 16
-2

const obj =  [
    { Datum: '05.06.2021 21:00', 'Wind [m/s]': '5,7' },
    { Datum: '05.06.2021 20:00', 'Wind [m/s]': '5,4' }]
    
console.log(obj[0]['Wind [m/s]'])

console.log(Object.values(obj[0])[1]);
ikiK
  • 6,328
  • 4
  • 20
  • 40