Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove null values from an object from a database?

Simple I have an object that looks like this which is returned directly from a stored procedure in my chrome browser. How can I remove the ones that say null in javascript/angular 2?

Object

like image 658
CodeMan03 Avatar asked Sep 22 '17 14:09

CodeMan03


1 Answers

null seems to be the only falsy values, so you could do just

arr = arr.filter(Boolean);

If it's just an object with keys, you could do

var obj = {c1 : 's', c2 : 's', c3 : null, c4 : null};

Object.entries(obj).forEach( o => (o[1] === null ? delete obj[o[0]] : 0));

console.log(obj);
like image 152
adeneo Avatar answered Oct 08 '22 03:10

adeneo