With a data structure that looks like this:
Items : [
{
title : 'One',
value : 1,
},
{
title : 'Two',
value : 2,
}
]
How would I construct an array of the titles from Items? As in ['One', 'Two']
This codeset generates a 'SyntaxError: Unexpected identifier' if titles == [] {..
app.get('/', function(req, res){
var titles = [];
for (var i=0, length=Items.length; i < length; i++) {
if titles == [] {
titles += Items[i]['title'];
}
else {
titles = titles + ', ' + Items[i]['title'];
}
console.log(titles);
};
res.render('items', {
itemTitles: titles
});
});