function hasAllProperties(obj, requiredKeys) {
return requiredKeys.every(key =>
Object.prototype.hasOwnProperty.call(obj, key) &&
obj[key] !== null &&
obj[key] !== undefined &&
obj[key] !== ""
);
}
const user = { name: "Alice", age: 25, email: "test@example.com" };
console.log(hasAllProperties(user, ["name", "age", "email"])); // true
const invalidUser = { name: "Bob", age: null };
console.log(hasAllProperties(invalidUser, ["name", "age", "email"])); // false
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme