Skip to content

Instantly share code, notes, and snippets.

@zereraz
Created July 20, 2015 16:33
Show Gist options
  • Save zereraz/0e7ff9c46c3b8c89eef5 to your computer and use it in GitHub Desktop.
Save zereraz/0e7ff9c46c3b8c89eef5 to your computer and use it in GitHub Desktop.
node null check example
var http = require('http');
var nullList = [];
function process(key,value) {
if(value === null || value === undefined){
nullList.push({
'key':key,
'value': value
})
}
}
function traverse(o,func) {
for (var i in o) {
func.apply(this,[i,o[i]]);
if (o[i] !== null && typeof(o[i])=="object") {
traverse(o[i],func);
}
}
}
http.globalAgent.maxSockets = undefined;
traverse(http, process);
console.log(nullList);
//output
//[ { key: 'domain', value: null },
//{ key: 'maxSockets', value: undefined } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment