In javascript return member of an object by reference
<p>I have a json object which is variable (with possibly infinite sub-structures):</p>

<pre><code>var myObject={
    s1:{
        s2:'2',
        s3:'3'
    },
    s4:'4',
    s5:{
        s6:undefined
    },
    s7:'7'
};
</code></pre>

<p>I would like to find the first undefined member and to return it's reference,
to be able to modify it anytime (by event triggered functions)</p>

<pre><code>function findFirstUndefined(obj){
    for (var key in obj){
        if (typeof(obj[key]) === 'object'){
            var recursion=findFirstUndefined(obj[key])
            if (recursion!==false){
                return recursion;
            }       
        }
        else if (obj[key]===undefined){
            return obj[key];
        }   
    }
    return false; 
}
</code></pre>

<p>But it doesn't return the reference of the member, but it's value:</p>

<pre><code>var subObj=findFirstUndefined(myObject);
subObj="my updated cool var!!";
</code></pre>

<p>doesn't modify the object.</p>

<p>I found that a library like <a href="http://goessner.net/articles/JsonPath/" rel="nofollow" title="JsonPath">JsonPath</a> could do the trick,
but it seems to me kind of heavy for such a simple task.</p>

<p>Wouldn't it exists an elegant way to do so? Thank's!</p>
