Closed marti1125 closed 8 years ago
@marti1125 You need to put var titles = []
outside your readable
event handler. You should expect the readable
event to fire many times, which means that currently, each time it fires you create a new, empty titles
array. That's why you only see the last one.
thanks! @danmactough you give me an idea how to solve my problem =D the solution is
var titles = []
var chunk;
feedparser.on('readable', function() {
// This is where the action is!
var stream = this
, meta = this.meta
, item;
while (chunk = stream.read()) {
titles.push(chunk.title)
}
});
feedparser.on('end', function() {
res.render('index', { title: 'Express', data: titles });
});
:tada:
I would like to print all titles but only get the last