Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
94
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
Building AI with AI
inesmontani
PRO
1
470
エディターってAIで操作できるんだぜ
kis9a
0
600
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
350
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
450
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
16
6.2k
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
220
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
200
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
6
1.2k
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
5.8k
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
290
俺流レスポンシブコーディング 2025
tak_dcxi
13
7.1k
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
110
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Fireside Chat
paigeccino
41
3.7k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
A Modern Web Designer's Workflow
chriscoyier
697
190k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Site-Speed That Sticks
csswizardry
13
980
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