My JSON data stored in dataTest.json data goes as follows :
"1":"value1",
"2":"value2"
}
The above gives positive results in a validator.
Now if I want to use this data in a javascript program like
var data = require('./dataTest.json');
console.log(data.1)
I get an error saying
console.log(data.1)
^^^^^^^^^
SyntaxError: missing ) after argument list
But simply changing the first key to something like a1
instead of simply 1
and calling it like data.a1
fixes it.
For several reasons, I'd like to keep the keys as simple numbers. Is there any way to refer to such keys with numerical values?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/E6cCouG
Comments
Post a Comment