checkAll = (data, key) => {
return key.split(".").reduce((o, k) => {
return (typeof o === 'undefined' || o === null) ? o : o[k];
}, data)
}
Example, if we want to check error response from axios, we could call with:
axios.get()
.then()
.catch(e => {
const message = this.checkAll(e, "response.data.message");
if (message !=== undefined && ...) {
// Do something
}
})