doc: document array.clone()

pull/7314/head
Alexander Medvednikov 2020-12-14 00:37:09 +01:00
parent ecfd124390
commit b9bf7a6583
1 changed files with 8 additions and 2 deletions

View File

@ -534,8 +534,7 @@ The type of an array is determined by the first element:
* `[1, 2, 3]` is an array of ints (`[]int`).
* `['a', 'b']` is an array of strings (`[]string`).
If V is unable to infer the type of an array,
the user can explicitly specify it for the first element: `[byte(16), 32, 64, 128]`.
The user can explicitly specify the for the first element: `[byte(16), 32, 64, 128]`.
V arrays are homogeneous (all elements must have the same type).
This means that code like `[1, 'a']` will not compile.
@ -595,6 +594,13 @@ Note: The above code uses a [range `for`](#range-for) statement.
All arrays can be easily printed with `println(arr)` and converted to a string
with `s := arr.str()`.
Copying the data from the array is done with `.clone()`:
```v nofmt
nums := [1, 2, 3]
nums_copy := nums.clone()
```
Arrays can be efficiently filtered and mapped with the `.filter()` and
`.map()` methods: