I am trying to validate the request object to check if specific keys exist in the object or not. I've tried lodash's has() function, but it seems that _.has() checks nested JSON. JavaScript's .hasOwnProperty() takes one key at a time. Is it possible to check an array of keys within a plain JSON object?
The object I am trying to check is:
{
"name": "[email protected]",
"oldPassword": "1234",
"newPassword": "12345"
}
obj.name && obj.oldPassword && obj.newPassword? If you want to check for a fixed structure, you need to have some sort of types like Typscript provides for example.