delete 運算子
更新:2007 年 11 月
刪除物件的屬性、移除陣列的元素或移除 IDictionary 物件中的項目。
delete expression
引數
- expression
必要項。任何會產生屬性參考、陣列元素或 IDictionary 物件的運算式。
備註
如果 expression 的結果為物件,則在 expression 中所指定的屬性便會存在,而且物件也不允許刪除該屬性,最後會傳回 false。
在其他的情況下則一律傳回 true。
範例
下列範例說明如何使用 delete 運算子。
// Make an object with city names and an index letter.
var cities : Object = {"a" : "Athens" , "b" : "Belgrade", "c" : "Cairo"}
// List the elements in the object.
var key : String;
for (key in cities) {
print(key + " is in cities, with value " + cities[key]);
}
print("Deleting property b");
delete cities.b;
// List the remaining elements in the object.
for (key in cities) {
print(key + " is in cities, with value " + cities[key]);
}
本程式碼的輸出為:
a is in cities, with value Athens
b is in cities, with value Belgrade
c is in cities, with value Cairo
Deleting property b
a is in cities, with value Athens
c is in cities, with value Cairo