function get_replies(currentObject, result) {
result.push({
author: currentObject.author,
text: currentObject.text
});
if (currentObject.replies) {
for (var i = 0; i < currentObject.replies.length; i += 1) {
get_replies(currentObject.replies[i], result);
}
}
return result;
}
console.log(get_replies(data, []));
Output
[ { author: 'John', text: 'Hi there' },
{ author: 'Henry', text: 'Hi John, did you get me that paper?' },
{ author: 'John', text: 'Which one?' },
{ author: 'Henry', text: 'Never mind. Let\'s catch up later' },
{ author: 'Frank',
text: 'The analysis sheet we talked about at the last meeting man!' },
{ author: 'John',
text: 'Oh that! Let me get back to you by the end of the day' },
{ author: 'Barry',
text: 'Call me about that last years report please when you find the time' },
{ author: 'John', text: 'About 5 good?' },
{ author: 'Barry', text: 'Yes, thank you' } ]