mirror of
https://github.com/typst/typst
synced 2025-06-28 08:12:53 +08:00
Document behaviour of dictionary.insert() when key exists (#282)
This commit is contained in:
parent
a4a915cc5c
commit
d0782b1853
@ -663,6 +663,7 @@ instead of integers. You can access and create dictionary entries with the
|
|||||||
[field access notation]($scripting/#fields) (`.key`) to access
|
[field access notation]($scripting/#fields) (`.key`) to access
|
||||||
the value. Dictionaries can be added with the `+` operator and
|
the value. Dictionaries can be added with the `+` operator and
|
||||||
[joined together]($scripting/#blocks).
|
[joined together]($scripting/#blocks).
|
||||||
|
To check whether a key is present in the dictionary, use the `in` keyword.
|
||||||
|
|
||||||
You can iterate over the pairs in a dictionary using a
|
You can iterate over the pairs in a dictionary using a
|
||||||
[for loop]($scripting/#loops).
|
[for loop]($scripting/#loops).
|
||||||
@ -686,6 +687,7 @@ special `(:)` syntax to create an empty dictionary.
|
|||||||
#dict.values() \
|
#dict.values() \
|
||||||
#dict.at("born") \
|
#dict.at("born") \
|
||||||
#dict.insert("city", "Berlin ")
|
#dict.insert("city", "Berlin ")
|
||||||
|
#("name" in dict)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
@ -706,6 +708,7 @@ Fails with an error if the key is not part of the dictionary.
|
|||||||
|
|
||||||
### insert()
|
### insert()
|
||||||
Insert a new pair into the dictionary and return the value.
|
Insert a new pair into the dictionary and return the value.
|
||||||
|
If the dictionary already contains this key, the value is updated.
|
||||||
|
|
||||||
- key: string (positional, required)
|
- key: string (positional, required)
|
||||||
The key of the pair that should be inserted.
|
The key of the pair that should be inserted.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user