-3

I am accessing data from an excel sheet and the table header is in number format (eg:2005-06) as below:

I want to access the data but I am getting an error while I try to access using objects. This is my console which is showing the fetched data:

This is the code I have written and getting an error:

enter image description here

How should I access this data? Note: I cannot change the names of the fields.

3 Answers3

0

use d['2004-05'] you can check about object key accessors here more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors

Faizal Hussain
  • 1,551
  • 2
  • 10
  • 18
0

Because the key contains -, you need to use key accessors.

For example

d["2004-05"]
Mina
  • 14,386
  • 3
  • 13
  • 26
0

You have to do:

<td>{d.['2004-05']}</td>
<td>{d.['2005-06']}</td>
<td>{d.['2006-07']}</td>
<td>{d.['2007-08']}</td>
<td>{d.['2009-10']}</td>
<td>{d.['2010-11']}</td>
<td>{d.['2011-12']}</td>
Mavrick RMX'
  • 108
  • 11