From 8d9f38f67034d4782bb13d5aa9c7dcd46b09366f Mon Sep 17 00:00:00 2001 From: Maciej Obarski Date: Wed, 5 Aug 2020 01:46:04 +0200 Subject: [PATCH] doc: 2d array example (#6058) --- doc/docs.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 8ac9ff5b21..04f5b4b45b 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -524,6 +524,24 @@ println(upper) // ['HELLO', 'WORLD'] `it` is a builtin variable which refers to element currently being processed in filter/map methods. +#### Multidimensional Arrays + +Arrays can have more than one dimension. + +2d array example: +```v +mut a := [][]int{len:2, init: []int{len:3}} +a[0][1] = 2 +println(a) // [[0, 2, 0], [0, 0, 0]] +``` + +3d array example: +```v +mut a := [][][]int{len:2, init: [][]int{len:3, init: []int{len:2}}} +a[0][1][1] = 2 +println(a) // [[[0, 0], [0, 2], [0, 0]], [[0, 0], [0, 0], [0, 0]]] +``` + ### Maps ```v