JSFiddle - React, Tailwind, and code Playground
HTML
https://jsfiddle.net/#
JavaScript
const obj = {
content: [
{ text: "paragraph 1" },
{ content: [
{ text: "paragraph 2" },
]
},
{ text: "paragraph 3" },
{ content: [
{ text: "paragraph 4" },
{ content: [
{ text: "paragraph 5" },
]
}
]
}
]
}
let lastItem = {};
function recursive(node) {
if (node.content) {
node.content.map(element => recursive(element));
} else if (node.text) {
lastItem = node.text;
}
}
obj.content.map(node => recursive(node));
console.log(lastItem + " - last item");