可能是一个愚蠢的问题,假设我有一个像下面这样的对象,
{"Country":"country","Continent":"continent","Province":"","District":"","State":"state","City":""}"
Run Code Online (Sandbox Code Playgroud)
在不使用循环的情况下,检查哪些属性保存上述对象中的值的最快方法是什么?
在for循环中执行此操作时,
if(typeof someUndefVar == whatever) -- works
Run Code Online (Sandbox Code Playgroud)
预期产量:
国家,大陆和国家
var a = {"Country":"country","Continent":"continent","Province":"","District":"","State":"state","City":""};
Object.keys(a).filter( prop => a[prop] );
Run Code Online (Sandbox Code Playgroud)
这也取决于你想如何处理0,null,undefined值.