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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nathan Youngman
May 25, 2015
Programming
170
0
Share
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
120
Go and Node.js: a comparison
nathany
1
250
Diet Hacks
nathany
2
390
Go 1.6 and HTTP/2
nathany
3
160
Upgrading Rails Redux
nathany
1
100
GopherCon recap
nathany
0
190
Go Functions
nathany
0
110
Go Types
nathany
2
140
Go Packages
nathany
2
570
Other Decks in Programming
See All in Programming
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
170
AI-DLC Deep Dive
yuukiyo
9
4.7k
Running Swift without an OS
kishikawakatsumi
0
850
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
640
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
790
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
170
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
170
AIエージェントで業務改善してみた
taku271
0
540
AIを導入する前にやるべきこと
negima
2
100
感情を設計する
ichimichi
5
1.5k
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
230
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
110
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
230
Tell your own story through comics
letsgokoyo
1
900
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Thoughts on Productivity
jonyablonski
76
5.1k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Un-Boring Meetings
codingconduct
0
270
Accessibility Awareness
sabderemane
1
100
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
110
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