Answer the question
In order to leave comments, you need to log in
Why does a method return undefined during recursion?
Here I have a method in a class and for some reason it returns undefined during recursion .
async getDogApi() {
try {
const result = await axios.get('https://random.dog/woof.json');
const posts = result.data;
const format: string = posts.url.substr(posts.url.length - 4);
if (format != '.jpg' /*|| '.PNG' || '.JPG' || '.png' || 'JPEG' || 'jpeg'*/) {
await this.getDogApi();
} else {
console.log(posts)
return posts;
}
} catch (err) {
return null;
}
console.log(await apiService.getDogApi());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question