使用 Underscore has() 检查嵌套属性

checking nested properties using Underscore has()

你如何处理这种情况?

_.has(item.attributes.format,'dateUpdated')

但您注意到有时 "format" 也不存在。你这样查吗

if (_.has(item.attributes,'format')) {
  if (_.has(item.attributes.format,'dateUpdated')) {
    // ok, I'm sure it exists
  }
}

ideal/professional/seasoned程序员检查它的方法是什么?

最新的 Lodash has() (https://lodash.com/docs#has) 支持 a.b.c 格式。您可以使用 _.has(item, 'attributes.format.dateUpdated').