删除 json 元素 - JavaScript?
javascriptweb developmentfront end technologyobject oriented programming
假设以下是我们的 JSON 字符串减去
var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", customerAge: 26 }, { customerName: "Bob", customerAge: 29 }, { customerName: "Carol", customerAge: 25 } ]
要删除 JSON 元素,请在 JavaScript 中使用 delete 关键字。
示例
以下是删除 JSON 元素的完整代码 −
var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", customerAge: 26 }, { customerName: "Bob", customerAge: 29 }, { customerName: "Carol", customerAge: 25 } ] delete details[0].customerAge; console.log(details);
要运行上述程序,您需要使用以下命令 −
node fileName.js.
这里我的文件名是demo211.js −
PS C:\Users\Amit\JavaScript-code> node demo211.js [ { customerName: 'Chris' }, { customerName: 'David', customerAge: 26 }, { customerName: 'Bob', customerAge: 29 }, { customerName: 'Carol', customerAge: 25 } ]