Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

filter out undefined from object javascript

const obj = {key1: undefined, key2: '', key3: 0, key4: null}

Object.keys(obj).forEach(key => obj[key] === undefined ? delete obj[key] : {});

// obj is now without key1 i.e. {key2: '', key3: 0, key4: null}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #filter #undefined #object #javascript
ADD COMMENT
Topic
Name
4+1 =