21

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?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Onyx
  • 5,186
  • 8
  • 39
  • 86

1 Answers1

24

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

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

Cisco
  • 20,972
  • 5
  • 38
  • 60