3 回答
TA贡献1854条经验 获得超8个赞
Object.values与 一起使用Array.prototype.some:
const obj = {
id: '123abc',
carrier_name: 'a',
group_id: 'a',
member_id: 'a',
plan_name: 'a',
}
console.log(!Object.values(obj).some(val => val === ""))
const obj2 = {
id: '123abc',
carrier_name: '',
group_id: 'a',
member_id: 'a',
plan_name: 'a',
}
console.log(!Object.values(obj2).some(val => val === ""))
TA贡献1798条经验 获得超7个赞
简单的循环和检查
const obj = {
id: '123abc',
carrier_name: 'a',
group_id: 'a',
member_id: '',
plan_name: '',
}
const checkIfEmpty = obj => {
for (const property in obj) {
if (obj[property].length === 0) {
return true
}
}
return false
}
console.log(checkIfEmpty(obj))
TA贡献1845条经验 获得超8个赞
如果您只有 strings ,您可以使用everyandBoolean作为回调进行检查。
const check = object => Object.values(object).every(Boolean);
console.log(check({ foo: 'bar' })); // true
console.log(check({ foo: '' })); // false
console.log(check({ foo: '', bar: 'baz' })); // false
console.log(check({ foo: '', bar: '' })); // false
添加回答
举报