0

I have this code so far:

function print_r( obj ) {
    if((typeof(obj)) == 'object' ) {
        var output = [];

        for(var x in obj) {
            if((typeof(obj[x])) == 'object') {
                output.push( print_r(obj[x]) );
            } else {
                output.push( x + ' => "' + obj[x].toString() + '"' );
            }
        }

        return output.join("\n");
    }

    return obj;
}

It does some basic recursion, but it's not good at this point.

How can I make this JavaScript function behave as PHP's print_r function?

EDIT: With tab indents if the loop accours on a new object within the parent object.

4

1 回答 1

1

为您的浏览器安装 Firebug:

console.log(myvar);
于 2013-07-02T12:19:36.493 回答