Javascript: How to print objects in Jrunscript?

Jrunscript has a function 'print'. However, it does not print anything useful about objects. For instance:

js> var obj = {one:1, two:2}

When evaluating an object, Jrunscriptonly this is displayed:

js> obj  

[object Object]

And 'print'also not good:

js> print(obj)

[object Object]js> 

What functions Jrunscriptcan be used to print the structure of an object?

+5
source share
1 answer

use rhino + env.js:

http://www.envjs.com/

Example:

load('env.rhino.1.2.js');
var t1 = {// 10
    "1" : {
        "q0" : "q1",
    },
    "0" : {
        "q1" : "q2"
    }
};
print(JSON.stringify(t1));

Of course, you get other useful things, but it helps you at the moment.

+2
source

All Articles