Answer the question
In order to leave comments, you need to log in
How to check for the existence of data more concisely?
this.loadData().then(response => {
if (response && response.data && response.data.users && response.data.users.length) {
this.usersLocal = response.data.users
}
})
Answer the question
In order to leave comments, you need to log in
there are libraries to simplify this task, for example, dot-object
and there is try .. catch
I don't see a problem with checking 4 conditions. You can move line by line:
this.loadData().then(response => {
if (
response
&& response.data
&& response.data.users
&& response.data.users.length
) {
this.usersLocal = response.data.users
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question