屬性的刪除

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

你可以使用 delete 運算子移除屬性。下面的代碼示範如何移除屬性︰

js
// 建立新的物件 myobj,以及兩個屬性 a 和 b。
myobj = new Object();
myobj.a = 5;
myobj.b = 12;

// 移除一個屬性,只剩 b 屬性留在 myobj 裡。
delete myobj.a;

你也可以使用 delete 來刪除全域變數,只要這個變數不是使用 var 關鍵字宣告的話︰

js
g = 17;
delete g;

參閱 delete 取得更多資訊。

io error: No such file or directory (os error 2) (/home/runner/work/yari/yari/mdn/content/files/en-us/core_javascript_1.5_教學_colon_新物件的建立_colon_getter_和_setter_的定義/index.md)