I have JSON data in another file, I am accessing that from a module file. I am using a loop to get lots of data easily but I am stuck on a problem. When using dot notation it goes cars.c1.name
, but in my example it is cars.c+i+
.. and then it stops because I don't know how to add .name
to that.
This is for a test project, I have tried googling but it is a particular issue.
Snippet of the JSON:
"c1": {
"id": 1,
"name": "Sprinter Boxtruck",
"make": "Mercedes",
"price": "£500,000",
"topspeed": "87mph",
"vip": "false"
},
The constant in question:
const carName = cars.c+i+.name; // not working
i
is the constant with which I am using the loop.
Expected result would be for me to have 4 different objects, actual - There is no error thrown but it doesn't work.