Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Replace empty strings in object with null values

const obj = {
  value1: 'bacon',
  value2: '',
  value3: 'lard',
  value4: '',
  value5: 'cheese',
};

Object.keys(obj).reduce((acc, key) => {acc[key] = obj[key] === '' ? null : 
obj[key]; return acc; }, {})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Replace #empty #strings #object #null #values
ADD COMMENT
Topic
Name
8+2 =