How to return an Object Value if you have a specific key in your Object? [duplicate]

// If successfully created
let sampleObject = {
response: ‘Generated ID from the application’
}

// If error
let sampleObject = {
errorLog: ‘Generated error message from the application’
}

I have an object that returns different keys depending if it is successful or an error (see above sample code). If it is successful, it has a key of ‘response’ and has a value of ID generated, otherwise it has a key of ‘errorLog’ and has a value of the error message. Now I want to run an if statement with those keys. For example, if the key ‘response’ is present, I want to alert the user for the generated ID for successfully creating the data. But if the key ‘errorLog’ is present, I want to alert the user for the error message.

Can someone help me?