0

I am currently trying to use the string "region" to find a specific part of JSON in my JSON file.

ex. config.regions.${region} being equal to config.regions.northeast (assuming hooks[i].regions[c] == northeast)

        for (var c = 0; c < hooks[i].regions.length; c++) {
            let region = JSON.stringify(hooks[i].regions[c]);

            if (config.regions.`${region}`.includes(city)) {
                webhook = config.hooks[i].webhook;
                post(webhook, title, price, link, img, city, keyword);

            }
        }
  • your question is not clear. see https://stackoverflow.com/help/how-to-ask. – viz Jan 27 '19 at 17:15
  • Possible duplicate of [How do I create a dynamic key to be added to a JavaScript object variable](https://stackoverflow.com/questions/2462800/how-do-i-create-a-dynamic-key-to-be-added-to-a-javascript-object-variable) – noahnu Jan 27 '19 at 17:31

1 Answers1

0

If I understand well your question. I believe you should be using the array syntax to access your object:

for (var c = 0; c < hooks[i].regions.length; c++) {
        let region = JSON.stringify(hooks[i].regions[c]);

        if (config.regions[region].includes(city)) {
            webhook = config.hooks[i].webhook;
            post(webhook, title, price, link, img, city, keyword);

        }
    }
gihef
  • 240
  • 1
  • 8