4

I'm parsing a website which contains stuff like

hmapId[7]='42500000000626135';
hmapStartInterv[7]='750';
hmapEndInterv[7]='846';
hmapUrlInterv[7]='some url';
hmapNameInterv[7]="some name"
hmapRoleInterv[7]='some role';

My plan is to write that into a .js file and execute it with node js. After that I want to have some lines of code giving me all variables defined before as JSON to use the data in some other program. What's the best way to do this?

Thanks

2
  • 1
    If you mean something like get_defined_vars in php, I guess thats not possible in javascript.
    – gopi1410
    Commented Jul 12, 2012 at 6:04
  • It's not possible: stackoverflow.com/questions/2051678/… You can parse it with regex...
    – Charles
    Commented Jul 12, 2012 at 6:33

1 Answer 1

2

For the current scope, it's not possible (AFAIK), for the global scope you have the globalobject in node.js (window in navigator embedded js engines), which get the global variables properties:

// on global scope, with x not defined as a "var"
x=25
console.info(global['x']===x) // --> writes down 'true'
2
  • Thanks, that did it for my case, global scope is sufficient :)
    – Florian
    Commented Jul 12, 2012 at 8:52
  • Be aware that the global object contains Everything that's global, even Funtion, Object, other modules, etc.,,
    – Julien Ch.
    Commented Jul 12, 2012 at 9:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.