在 Javascript 中,我有一个对象,我想删除多个键:
x = {"id":2,"user_id":1,"name":"document_name","description":"the document","file_type":null,"file_id":null}
delete x.file_type
delete x.file_id
结果:
Object {id: 2, user_id: 1, name: "document_name", description: "the document"}
我更愿意在一个命令中删除所有键,也许传递一个键数组?
或者,使用某种类型的下划线/lodash 过滤器来实现相同的目标。
最佳答案
['file_type', 'file_id'].forEach(function (key) {
delete x[key];
});
关于javascript - 删除键列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27734731/