These are the arrays:
[ 'markdown',
[ 'para', 'this is a paragraph' ],
[ 'para', {class: 'custom-class'}, 'another paragraph' ],
[ 'hr' ],
[ 'bulletlist',
[ 'listitem', 'This is a list' ],
[ 'listitem', 'This is another list' ] ] ]
What I want to do is to find the last string in each of them. In this case, 'this is a paragraph', 'another paragraph', 'This is a list', 'This is another list'. (I'm not interested in arrays with only one string, in this case, hr. But I guess that's another SO question.)
The best I could achieve was this:
for (i = 1; i < tree.length; i++) {
var node = tree[i]
var lastItem = node[node.length - 1]
console.log(lastItem)
}
\\ this is a paragraph
\\ {class: 'custom-class'}
\\ hr
\\ [ 'listitem', 'This is a list' ]
\\ [ 'listitem', 'This is another list' ]
I think you can see the problem, though 1) the loop sometimes find a nested array/object 2) it's not recursive.
How should I modify the loop so it always find the last string of these arrays?
hris the last string in[ 'hr' ]. Why that is not included?