How to extend an object while ignoring null values?
<p>Say for example I have an object of</p>

<pre><code>var user = { 
    "Name": "Dan", 
    "Age": 27, 
    "Hobbies": null 
};
</code></pre>

<p>which I would like to merge onto the following base object so that my user object will have all the required properties</p>

<pre><code>var base = { 
    "Name": null, 
    "Height": null, 
    "Age": null, 
    "Hobbies": [
        { "Name": "Tennis", "Location": null },
        { "Name": "Football", "Location": null },
        { "Name": "Rugby", "Location": null }
    ]
};
</code></pre>

<p>The easiest way to merge to the two objects would be to extend the base object with the user object as follows</p>

<pre><code>$.extend(true, base, user);
</code></pre>

<p>which would modify the base object to be</p>

<pre><code>{ 
    "Name": "Dan", 
    "Height": null, 
    "Age": 27, 
    "Hobbies": null
};
</code></pre>

<p>My question would be how can I get the extend method to not override null values? For example, in this instance, how can I still obtain a list of hobbies if the users hobby list is null so I end up with the following</p>

<pre><code>{ 
    "Name": "Dan", 
    "Height": null, 
    "Age": 27, 
    "Hobbies": [
        { "Name": "Tennis", "Location": null },
        { "Name": "Football", "Location": null },
        { "Name": "Rugby", "Location": null }
    ]
};
</code></pre>
