Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
0
150
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Tweet
Share
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
110
Go and Node.js: a comparison
nathany
1
230
Diet Hacks
nathany
2
380
Go 1.6 and HTTP/2
nathany
3
140
Upgrading Rails Redux
nathany
1
96
GopherCon recap
nathany
0
180
Go Functions
nathany
0
100
Go Types
nathany
2
130
Go Packages
nathany
2
560
Other Decks in Programming
See All in Programming
sbt 2
xuwei_k
0
290
WebRTC と Rust と8K 60fps
tnoho
2
2k
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
1
690
20 years of Symfony, what's next?
fabpot
2
350
Github Copilotのチャット履歴ビューワーを作りました~WPF、dotnet10もあるよ~ #clrh111
katsuyuzu
0
110
ZOZOにおけるAI活用の現在 ~モバイルアプリ開発でのAI活用状況と事例~
zozotech
PRO
8
5.6k
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
450
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
130
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.4k
ゲームの物理 剛体編
fadis
0
340
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
160
Go コードベースの構成と AI コンテキスト定義
andpad
0
120
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Site-Speed That Sticks
csswizardry
13
1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Being A Developer After 40
akosma
91
590k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Agile that works and the tools we love
rasmusluckow
331
21k
Why Our Code Smells
bkeepers
PRO
340
57k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
GraphQLとの向き合い方2022年版
quramy
50
14k
The Pragmatic Product Professional
lauravandoore
37
7.1k
KATA
mclloyd
PRO
32
15k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Transcript
gophers := [4]string{"blue", "pink", "purple", "blue"}
Arrays are fixed-length planets := [8]string{ "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", } 0 1 2 3 4 5 6 7
Arrays are values planetBackup := planets // make way
for an interstellar bypass planets[2] = “" fmt.Println(planets) // [Mercury Venus Mars Jupiter Saturn Uranus Neptune] fmt.Println(planetBackup) // [Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune]
Slicing makes a window terrestrial := planets[0:4] gasGiants := planets[4:6]
iceGiants := planets[6:8] 0 1 2 3 4 5 6 7 terrestrial gasGiants iceGiants
Half-open range planets[2:3] // [Earth] < 3 • starts at
index 2 • excludes index 3
Defaults terrestrial := planets[:4] gasGiants := planets[4:6] iceGiants := planets[6:]
allPlanets := planets[:]
Making a slice // allPlanets := planets[:] planets := []string{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", }
Append to slices planets = append(planets, "Pluto") 0 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 fmt.Println(len(planets), cap(planets)) // 9 16
Append again planets = append(planets, "Eris", "Sedna") fmt.Println(len(planets), cap(planets))
// 11 16
http://blog.golang.org/go-slices-usage-and-internals https://github.com/golang/go/wiki/SliceTricks More reading