我有一个包含一些键值对的变量数据,如下所示:
var data = {
"1": 127,
"2": 236,
"3": 348
}
router.delete('/values/:id', function(req, res, next){
var id = req.params.id;
})
如何删除键值等于id变量的键值对?
答案 0 :(得分:5)
delete data[req.params.id]
或delete data[id]
应该有效。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete