DEV Community

drew
drew

Posted on

TIL: How to Access the Inside of a Map in Elixir

This is one of those things that had slipped my mind. We covered it earlier in the Dockyard Academy, had to use it later so I had to look it up the syntax. Hopefully I'll remember it now :)

game = %{
team1_name: "Team Team",
team2_name: "Exersport",
round1: %{
team1: 10,
team2: 20
},
round2: %{
team1: 30,
team2: 10
},
round3: %{
team1: 25,
team2: 30
}
}

use dot(.) notation to access an element in a map:

`game.team1_name
"Team Team"

game.round2.team2
10

game.round1.team1 + game.round2.team1 + game.round3.team1
65
`
Hopefully this helps me (and maybe you!) remember.

Top comments (0)