JavaScript的Delete 删除操作符

JavaScript delete 操作符 能移除一个对象的属性,也可以移除一个数组的元素。

Delete 属性

JavaScript delete 操作符移除一个对象的属性; 如果没有更多的同样属性的引用,甚至会自动释放。

var Student = {
firstname: "John",
lastname: "Doe"
}
document.write(Student.firstname);
delete Student.firstname;
document.write(Student.firstname);

输出

John
undefined

从数组里面删除元素

var ar = new Array (0, 1, 2, 3, 4,5);
document.write (ar + "<br>");
delete ar[1];
document.write (ar);

输出

0,1,2,3,4,5
0,2,3,4,5
原文链接