Thursday 25 June 2020

Help with async recursive function

const getComments = async (commentData) => {if (!Array.isArray(commentData.data.replies)){console.log("bottom");return [commentData.data.body];    } else {for (reply of commentData.data.replies.data.children) {const tempComments =  await getComments(reply);tempComments.push(reply.data.body);console.log("step");return tempComments;      }    }};I'm using this on json I get from Reddit comments. Each comment has an array of replies unless it's the last comment in the thread. When it hits the last comment in the thread it returns that body. And then I want it to all the way back up the thread adding the comment of the body to an array and at the end have an array of comment bodies from threads. Am I calling this recursive function wrong?

Submitted June 25, 2020 at 06:27PM by laneherby

No comments:

Post a Comment