Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Transcript
10 slides
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
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
130
Go and Node.js: a comparison
nathany
1
290
Diet Hacks
nathany
2
420
Go 1.6 and HTTP/2
nathany
3
180
Upgrading Rails Redux
nathany
1
120
GopherCon recap
nathany
0
220
Go Functions
nathany
0
130
Go Types
nathany
2
160
Go Packages
nathany
2
590
Other Decks in Programming
See All in Programming
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
260
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
210
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
610
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
390
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
テストだけで見つかる? Rubyでつくるメソッド発掘器
izawa
0
160
はじめてのKubernetesコントリビューション
nasa9084
0
320
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
420
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
220
特急いなほ as a Workflow / 20261107jaws-festa-2026-akita-lt
kasacchiful
PRO
0
110
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
180
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
630
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
1
310
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
350
How to build a perfect <img>
jonoalderson
1
6.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Automating Front-end Workflow
addyosmani
1370
210k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
340
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
650
Mobile First: as difficult as doing things right
swwweet
225
10k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
380
HDC tutorial
michielstock
2
1k
Crafting Experiences
bethany
1
460