猿问

删除 object 中多个 key 有什么优雅的写法吗?

delete object.nid

delete object.uuid

delete object.desktop

delete object.isHide

delete object.sortId

delete object.dateBean

类似这种需要删除很多个元素的有什么优雅的写法吗?

慕森卡
浏览 415回答 1
1回答

四季花海

把key值放到一个数组中,然后循环删除key值:var keys = ["nid", "uuid", "desktop", "isHide", "sortId", "dateBean"];keys.forEach(function(item) {delete object[item]});
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答