# How to iterate over the tuple values and get both the key and the value?

**URL:** <https://forum.crystal-lang.org/t/how-to-iterate-over-the-tuple-values-and-get-both-the-key-and-the-value/6171>\
**Category:** Help & Support\
**Created:** [November 16, 2023, 12:22pm UTC](https://forum.crystal-lang.org/t/how-to-iterate-over-the-tuple-values-and-get-both-the-key-and-the-value/6171 "2023-11-16T12:22:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maverk41374](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@maverk41374](https://forum.crystal-lang.org/u/maverk41374)\
**Post date:** [November 16, 2023, 12:22pm UTC](https://forum.crystal-lang.org/t/how-to-iterate-over-the-tuple-values-and-get-both-the-key-and-the-value/6171/1 "2023-11-16T12:22:32Z")

</div>

```auto
array : NamedTuple(name: String, age: String) = {name: "crysal", age: "very long"}

(c,d).each() do |a, b| 
	puts a, b
end

```

i want to loop over the tuple and get both the key and the value how ?

---

<div class="post-metadata">

**Author:** ![crimson-knight](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/crimson-knight/32/1643_2.png) [@crimson-knight](https://forum.crystal-lang.org/u/crimson-knight)\
**Post date:** [November 16, 2023, 2:52pm UTC](https://forum.crystal-lang.org/t/how-to-iterate-over-the-tuple-values-and-get-both-the-key-and-the-value/6171/2 "2023-11-16T14:52:22Z")

</div>

Your code example is nearly correct  
[https://crystal-lang.org/api/1.10.1/NamedTuple.html#each(%26)%3ANil-instance-method](https://crystal-lang.org/api/1.10.1/NamedTuple.html#each%28%26%29%3ANil-instance-method)

```crystal
some_var : NamedTuple(name: String, age: String) = {name: "crysal", age: "very long"}

some_var.each() do |key, value| 
  puts key.to_s
  puts value
end

```

The syntax breakdown is:  
variable\_name : TheTypeYourAreSpecifying = `its_default_value`

So in your example you named your `NamedTuple` as `array`, which I think is causing some confusion.
