0

I was working on my discord bot when suddenly this problem occurred.

Usually, once you link a JSON file, you can get data by doing jsonFile.path to get some form of information.

I ran into a problem where I want to replace path with a variable's value.

Is there anyway that I could do this? In my case I am using a command randomly generate a number, check if that number is currently on the file, add it to the JSON file.

Daniel
  • 10,641
  • 12
  • 47
  • 85
NintendoZaedus
  • 653
  • 3
  • 8
  • 22

1 Answers1

0

So I figured this out awhile ago, and I forgot to put an answer but anyways this is how I can find information from an object path using a variable. Pretty much you can get information from a JSON object by doing the following

let object = {“name”: “John”}
let path = “name”;
console.log(object[path])
NintendoZaedus
  • 653
  • 3
  • 8
  • 22