Sajeetharan Sajeetharan - 1 year ago 55
Javascript Question

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

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


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


Country, Continent and State

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download