Created
May 12, 2016 09:40
-
-
Save AndrewAllison/c5d948b4a1d71a777788743a81bd4433 to your computer and use it in GitHub Desktop.
Removing nulls from a Javascript object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeNullIn(prop, obj) { | |
console.info('We dont want nulls..', prop, obj); | |
var pr = obj[prop]; | |
if (pr === null || pr === undefined) { | |
delete obj[prop]; | |
} | |
else if (typeof pr === 'object') { | |
for (var i in pr) { | |
removeNullIn(i, pr) | |
} | |
}; | |
} | |
function removeNull(obj) { | |
for (var i in obj) { | |
removeNullIn(i, obj); | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the original
http://stackoverflow.com/questions/28473889/angularjs-merge-two-objects-ignoring-null-and-missing-values