Sajeetharan Sajeetharan - 2 months ago 9
Javascript Question

Quickest way to check which property inside an object holds value?

Probably a dumb question, Assume i have an object like below,

{"Country":"country","Continent":"continent","Province":"","District":"","State":"state","City":""}"


What is the quickest way to check which properties hold the values in the above object without using a loop?

while doing this inside a for loop is working,

if(typeof someUndefVar == whatever) -- works


EXPECTED OUTPUT:

Country, Continent and State

Answer
var a = {"Country":"country","Continent":"continent","Province":"","District":"","State":"state","City":""};

Object.keys(a).filter( prop => a[prop] );

It also depends on how you want to handle the 0, null, undefined values.