javascript - node.js , ^ SyntaxError: Unexpected token ] -
this code :
app.get("/posts/:slug", function(request, response) { var slug = request.params.slug; connection.query("select * `posts` slug = ?", [ slug ], function(err, rows) { var post = rows[]; response.render("post", { post: post, formatdate: formatdate }); }); }); when run index.js in terminal ;
/home/yasser/yasser/index.js:33 var post = rows[]; ^ syntaxerror: unexpected token ]
the error syntaxerror: unexpected token ] produced because var post = rows[]; invalid. when gets [ next thing expects number (or string) represents index of item in array.
for example, if change var post = rows[0]; you'll first element in array.
Comments
Post a Comment