-
哔哔one
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 === ""))
-
元芳怎么了
简单的循环和检查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))
-
精慕HU
如果您只有 strings ,您可以使用everyandBoolean作为回调进行检查。const check = object => Object.values(object).every(Boolean);console.log(check({ foo: 'bar' })); // trueconsole.log(check({ foo: '' })); // falseconsole.log(check({ foo: '', bar: 'baz' })); // falseconsole.log(check({ foo: '', bar: '' })); // false