Skip to content
目录

判断对象属性是否为空

javascript
//判断对象属性是否都有值
Tool.isJsonNull = (obj, key) => {
  let keys = Object.keys(obj)
  // 过滤字段不需要判断
  if (key) {
    if (Array.isArray(key)) {
      keys = keys.filter(v => !key.includes(v))
    } else {
      keys = keys.filter(v => v !== key)
    }
  }
  let arr = keys.map(k => {
    return obj[k]
  })
  return !arr.includes('')
}

Released under the MIT License.