如何确定对象中的任何值是否为非空?

Ben*_*rts 0 javascript underscore.js

在 Javascript 中,我正在处理一些采用以下形式的 JSON 数据:

o = {
  a: null,
  b: null,
  c: 1,
  d: null
  // ... 10 or so other properties that are either null or numerical
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写一个快速函数,该函数将处理整个对象以确定任何键是否存在任何非空值。有什么建议可以只用几行代码有效地做到这一点吗?我的项目已经使用 underscore.js,所以如果这可以加快速度或使其更简洁,那就更好了。

ggo*_*zad 5

单线呢,

_.any(_.values(a), function (v) { return !_.isNull(v) });
Run Code Online (Sandbox Code Playgroud)

如果至少有一个非空值,它将返回 true。