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
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
240
Diet Hacks
nathany
2
390
Go 1.6 and HTTP/2
nathany
3
150
Upgrading Rails Redux
nathany
1
97
GopherCon recap
nathany
0
190
Go Functions
nathany
0
100
Go Types
nathany
2
140
Go Packages
nathany
2
560
Other Decks in Programming
See All in Programming
dchart: charts from deck markup
ajstarks
3
1k
Fluid Templating in TYPO3 14
s2b
0
130
ぼくの開発環境2026
yuzneri
0
240
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
430
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
160
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.6k
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
830
Visualization
eitanlees
150
17k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
150
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
93
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Automating Front-end Workflow
addyosmani
1371
200k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Speed Design
sergeychernyshev
33
1.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
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