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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -