I'd just create a utility that receives a list of properties to check.
function hasProperties(obj, ...names) {
return names.every(n => obj.hasOwnProperty(n))
}
if(hasProperties(req.body, 'first_name', 'last_name'))
{
//....
}
But .hasOwnProperty()
calls are usually avoidable with shorter checks, unless you actually allow Object.prototype
extensions in your code.
To answer the question directly, yes, but your desired solution would require such Object.prototype
extensions. I think they're far more trouble than they're worth.