You can do this using JSON or a JavaScript object instead of an array, like this:
"data" : {
"1000": "1000",
"1200": "1200",
"1400": "1400",
"1600": "1600",
"1800": "1800",
}
Note that the square brackets have been replaced with curly brackets. This signifies a JavaScript object, where each “key” has a “value” – for instance, the first key-value pair is "1000"
and "1000"
. If you want to assign this object to a JavaScript variable, you can do so like this:
var data = {
"1000": "1000",
"1200": "1200",
"1400": "1400",
"1600": "1600",
"1800": "1800",
}
To access these values, you can use data["1000"]
to access the property "1000"
– this will return the value "1000"
. You could use numbers as the values instead of strings, like this:
"data" : {
"1000": 1000,
"1200": 1200,
"1400": 1400,
"1600": 1600,
"1800": 1800,
}
Otherwise, you can convert the string values into numeric ones using parseInt()
or parseFloat()
:
parseInt(data["1000"]);
Hope this helps!