Thursday, November 8, 2018

javascript - How to delete key-value pair from an object?





I have a variable data that contains some key-value pairs like this:



var data = {
"1": 127,
"2": 236,

"3": 348
}

router.delete('/values/:id', function(req, res, next){
var id = req.params.id;

})


How can I delete the key-value pair that has a key equal to the id variable?



Answer



delete data[req.params.id] or delete data[id] should work.



https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...