Answers for "javascript remove empty object items"

0

javascript remove empty object items

var test = {
  test1: null,
  test2: 'somestring',
  test3: 3,
}

function clean(obj) {
  for (var propName in obj) {
    if (obj[propName] === null || obj[propName] === undefined) {
      delete obj[propName];
    }
  }
  return obj
}

console.log(test);
console.log(clean(test));
Posted by: Guest on February-09-2021

Code answers related to "javascript remove empty object items"

Code answers related to "Javascript"

Browse Popular Code Answers by Language