I want to read a set of variables that happen to be valid json objects from js files. The problem is, I don't know what the js file looks like(it is uploaded by users) and I only care about the variables I need.
For example, I got this file:
// xxx_file.js
const a = {"foo":"bar", "urls":["url1", "url2", "url2"]};
const b = {"username":"silk", "age":18};
// some functions or other variables
Now I need to read variable a and b from it, should I just use eval() or there're other ways to do it more easily?
Those variables are not necessarily
const, but I only need the value when they are declared, whether they are modified or not after initialization is not my concern.