Skip to content

Commit 9fe728a

Browse files
committed
Adds delete from slices eg
1 parent 78996da commit 9fe728a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
7+
/**
8+
* Blank [] will declare a slices.
9+
* If you provide size like [5] will declare an array.
10+
*/
11+
var employee []string
12+
13+
/**
14+
* Initialize a slices with type, length and capacity.
15+
* length is required field.
16+
*
17+
* make([]string, length, [capacity])
18+
*/
19+
employee = make([]string, 6)
20+
21+
employee[0] = "Ashwin"
22+
employee[1] = "Kumar"
23+
employee[2] = "Saju"
24+
employee[3] = "Ajay"
25+
employee[4] = "Vinayak"
26+
employee[5] = "Jerin"
27+
28+
fmt.Println("Slices: ", employee)
29+
30+
// 0:2 - include 0, 1 but excludes 2
31+
// 4: - include last
32+
// ... - expanding slices
33+
employee = append(employee[0:2], employee[4:]...)
34+
35+
fmt.Println("After Delete: ", employee)
36+
}

0 commit comments

Comments
 (0)