mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
docs: document explicitly, that maps support if v := m[k] {
too
This commit is contained in:
parent
c006d5c242
commit
63d15086e7
10
doc/docs.md
10
doc/docs.md
@ -1295,6 +1295,16 @@ mm := map[string]int{}
|
|||||||
val := mm['bad_key'] or { panic('key not found') }
|
val := mm['bad_key'] or { panic('key not found') }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also check, if a key is present, and get its value, if it was present, in one go:
|
||||||
|
```v
|
||||||
|
m := {
|
||||||
|
'abc': 'def'
|
||||||
|
}
|
||||||
|
if v := m['abc'] {
|
||||||
|
println('the map value for that key is: $v')
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
The same optional check applies to arrays:
|
The same optional check applies to arrays:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
|
Loading…
Reference in New Issue
Block a user