node.js - Deleting an object from a array in javascript -
i'm trying remove object cart using art_id, when i'm getting error syntaxerror: delete of unqualified identifier in strict mode.
why happening , how can modify code come on error
function remove_from_cart(req, res, next) { console.log(req.session); var art_id = req.params._id; var art_to_remove = _.findwhere(req.session.cart, { art_id: art_id }); console.log(art_to_remove); delete art_to_remove; console.log(req.session); res.send('deleted') }
since seems you're using underscore
, can use _.reject()
:
req.session.cart = _.reject(req.session.cart, { art_id: art_id });
Comments
Post a Comment