Slices

Wikipedia: Array slicing
Slices are a key data type in Tengo, giving a more powerful interface to sequences than arrays.

fmt := import("fmt")
s := ["a", "b", "c", "d", "e"]
fmt.println("base array: ", s)
l = s[:5]
fmt.println("sl2: ", l)
l = s[2:]
fmt.println("sl3: ", l)

try it

base array: ["a", "b", "c", "d", "e"]
sl1: ["b", "c"]
sl2: ["a", "b", "c", "d", "e"]
sl3: ["c", "d", "e"]
cpy: ["a", "b", "c", "d", "e"]
2d: [[0], [1, 2], [2, 3, 4]]
loading…