Javascript challenge

Nattsurfaren

Power Member
Joined
Apr 12, 2010
Messages
593
Reaction score
82
So I was trying to find a way to grab the email generated by temp-mail.org (not the api).
Usually the value in an input field is visible in the browser DOM inspector.
But for some reason they cleverly removed it.

I thought to myself that I wish I could find an overview of all nodes/objects. So that I could find where it is stored.
That would also help if I face this problem in other websites. I found this function to list the entire DOM.
Code:
var objs = []; // we'll store the object references in this array

function walkTheObject( obj ) {
    var keys = Object.keys( obj ); // get all own property names of the object

    keys.forEach( function ( key ) {
        var value = obj[ key ]; // get property value

        // if the property value is an object...
        if ( value && typeof value === 'object' ) {

            // if we don't have this reference...
            if ( objs.indexOf( value ) < 0 ) {
                objs.push( value ); // store the reference
                walkTheObject( value ); // traverse all its own properties
            }

        }
    });
}

walkTheObject( this ); // start with the global object

What I got back was a huge object tree.
I wish I could just output everything to a string and search in a simple text editor.
But all attempt has been failing so far.

Any ideas how to deal with this?
Appreciate your help.
 
To answer your original question though, if you want to turn a large nested object into a string, you can just use JSON.stringify().

JavaScript:
const someObject = {
    key1: 'woo',
    key2: 'hoo',
};

const someString = JSON.stringify(someObject, null, 2);

console.log(someString);

I didn't test that code, but it should be something like that.
 
Back
Top