Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
140
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
220
Diet Hacks
nathany
2
370
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
550
Other Decks in Programming
See All in Programming
10年もののAPIサーバーにおけるCI/CDの改善の奮闘
mbook
0
780
あなたの知らない「動画広告」の世界 - iOSDC Japan 2025
ukitaka
0
390
Playwrightはどのようにクロスブラウザをサポートしているのか
yotahada3
7
2.3k
ソフトウェア設計の実践的な考え方
masuda220
PRO
3
490
dynamic!
moro
9
6.6k
Web技術を最大限活用してRAW画像を現像する / Developing RAW Images on the Web
ssssota
2
1.2k
CSC305 Lecture 02
javiergs
PRO
1
260
そのpreloadは必要?見過ごされたpreloadが技術的負債として爆発した日
mugitti9
2
3k
CSC509 Lecture 05
javiergs
PRO
0
300
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
3.2k
Serena MCPのすすめ
wadakatu
4
900
クラシルを支える技術と組織
rakutek
0
190
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Writing Fast Ruby
sferik
629
62k
Mobile First: as difficult as doing things right
swwweet
224
10k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
Facilitating Awesome Meetings
lara
56
6.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6.1k
Context Engineering - Making Every Token Count
addyosmani
5
180
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
The Pragmatic Product Professional
lauravandoore
36
6.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
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