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?

2
  • There's no JSON there! Commented Dec 13, 2017 at 14:55
  • delete data[id] ?!? Commented Dec 13, 2017 at 14:55

1 Answer 1

24

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't expect it to be that easy!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.