Syntax
Deletes the entry of a key, or the current entry when no key is given.
DeleteMapElement(<map>() [, <key>])Parts
| <map> | The map, written with its empty parentheses: stock(). It must be a NewMap variable or a map field of a record. |
|---|---|
| <key> | Optional. The key to delete, turned into text. Without it, the current entry is deleted. |
Returns
1 when an entry was deleted, 0 when the key does not exist or there is no current entry.
Good to know
- When the deleted entry was the current one, the entry created just before it becomes current. Deleting the first entry leaves no current entry.
- Deleting the current entry inside
FOREACHis safe: the loop goes on with the next entry. - A handle made with
@m("key")is not cut by the deletion:IsRef()stays true, andGetRef()creates the entry again with the default value.
Example
NewMap hp.i()hp("orc") = 30hp("elf") = 10hp("imp") = 5FOREACH hp() IF hp() < 20 THEN DeleteMapElement(hp())NEXTConsole(Str(MapSize(hp()))) ' 1Console(Str(DeleteMapElement(hp(), "orc"))) ' 1Console(Str(DeleteMapElement(hp(), "orc"))) ' 0In the manual : Arrays, lists and maps