• 欢迎来到本站,本站主要做程序员相关技术、博客、笔记,如果喜欢本网站那么赶紧使用Ctrl+D 收藏吧!
  • 如果有任何疑问,可以在下方文章下方留下你的评论~

You can use the “delete” keyword to delete JavaScript object properties

电子书籍 9个月前 (09-28) 1次浏览 0个评论

Sometimes we use ajax to get a JSON object, but we don’t need some JavaScript object properties. How can we remove them?

delete operator

The JavaScript delete operator removes a property from an object;(MDN web docs)

const Employee = {
  firstname: 'John',
  lastname: 'Doe'
};

console.log(Employee.firstname);
// expected output: "John"

delete Employee.firstname;

console.log(Employee.firstname);
// expected output: undefined

Delete variable

You cannot delete variables with "delete operator"

var name = 'lily';
delete name;
console.log(name); //lily

Cannot delete the variable in the prototype chain

fun.prototype.age = 18;
delete obj.age;
console.log(obj.age) //18

中国笔友, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:You can use the “delete” keyword to delete JavaScript object properties
喜欢 (0)
发表我的评论
取消评论
表情 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址