I have a json that looks like this:
const sitesList =
{"sites": {
"miami": {
"name": "Miami Beach"
},
"london": {
"name": "London Bridge"
}
}}
I also have a function that takes an array as parameter. The values in this array might be "london", "miami" or both etc. This is the function:
async function readPDF2(sites) {
for (const value of sites) {
console.log(sitesList.sites.value.name);
}
}
The function is called like this: readPDF2(['miami']);
Now the problem is that when I do sitesList.sites.value.name
, Javascript interprets value
as an actual part of the json object. This makes sense, but how do I get around this? I want it to treat value
as the constant declared in the for loop.
See this image:
How would I obtain this? Thanks for any input!