D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
briankoech
Full window
Github gist
JS Bin // source https://jsbin.com/kacowi
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <script id="jsbin-javascript"> var myobj = { a: 90, b: undefined, c: { d: '909', e: {}, f: undefined } }; const isRealObj = (obj) => { return obj && typeof obj == 'object' && obj !== null && obj !== 'undefined'; } // loop through the item const sanitizeKey = (obj, key) => { if (typeof obj[key] == 'undefined') obj[key] = null; if (isRealObj(obj[key])) { // loop through it Object.keys(obj[key]).forEach(val => sanitizeKey(obj[key], val)); } } const sanitizer = (obj) => { Object.keys(obj).forEach(key => sanitizeKey(obj, key)); return obj; } var ok = sanitizer(myobj); console.log(ok); </script> <script id="jsbin-source-javascript" type="text/javascript">var myobj = { a: 90, b: undefined, c: { d: '909', e: {}, f: undefined } }; const isRealObj = (obj) => { return obj && typeof obj == 'object' && obj !== null && obj !== 'undefined'; } // loop through the item const sanitizeKey = (obj, key) => { if (typeof obj[key] == 'undefined') obj[key] = null; if (isRealObj(obj[key])) { // loop through it Object.keys(obj[key]).forEach(val => sanitizeKey(obj[key], val)); } } const sanitizer = (obj) => { Object.keys(obj).forEach(key => sanitizeKey(obj, key)); return obj; } var ok = sanitizer(myobj); console.log(ok); </script></body> </html>