[英]Remove a property from the object without using the Delete operator
I am learning about new
keywords and have homework 1. I wrote a code to remove a property from the object using the delete operator. 我正在学习new
关键字和做作业1.我编写了一个代码,使用delete运算符从对象中删除属性。 So is there any way I don't use delete operator, I still remove it? 那么有什么方法我不使用删除操作符,我仍然删除它? And using new
keyword? 并使用new
关键字?
var student = {
name : "David Rayy",
sclass : "VI",
rollno : 12
};
function updateObj() {
var result = delete student.rollno;
return student;
}
updateObj()
/* expect
var student = {
name : "David Rayy",
sclass : "VI",
};
*/
var student = {
name: 'Herry',
gender: 'male',
age: 18
}
function showInfo(obj) {
}
showInfo();
This question is a duplicate of "How do I remove a property from a JavaScript object?", because that question does discuss the alternative. 这个问题是“如何从JavaScript对象中删除属性?”的副本,因为该问题确实讨论了替代方案。
The "alternative", in this case, is student.rollno = undefined
. 在这种情况下,“替代”是student.rollno = undefined
。
This method also has the advantage of being 100 times faster than delete
. 该方法还具有比delete
快100倍的优点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.