删除运算符

从对象中删除属性,从数组中移除元素或从 IDictionary 对象中移除项。

delete expression

参数

  • 表达式
    必选。 任何结果为属性引用、数组元素或 IDictionary 对象的表达式。

备注

如果表达式 的结果是一个对象,且在表达式 中指定的属性存在,同时该对象不允许此属性被删除,那么将返回 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

要求

版本 3

请参见

参考

IDictionary

概念

运算符优先级

运算符摘要