# TMap access elements by index

**URL:** <https://forums.unrealengine.com/t/tmap-access-elements-by-index/329947>\
**Category:** C++\
**Tags:** tmap, unreal-engine, CPP, question\
**Created:** [August 26, 2015, 7:52am UTC](https://forums.unrealengine.com/t/tmap-access-elements-by-index/329947 "2015-08-26T07:52:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Constan7ine](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Constan7ine](https://forums.unrealengine.com/u/Constan7ine)\
**Post date:** [August 26, 2015, 7:52am UTC](https://forums.unrealengine.com/t/tmap-access-elements-by-index/329947/1 "2015-08-26T07:52:47Z")

</div>

I’m using a map to count votes for a voting system, so the vote string is the key, and the vote count is the value.

I sort the map to get the top vote, but now how do I access the top vote? A hack way of doing it I came up with was doing a for loop and breaking on the first iteration.

But what if there’s a tie? I need to check if the second element and first element have the same count?

I need to be able to access elements in ordered indices. Can I do that? Or is there something else that can help me?

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [August 26, 2015, 11:22am UTC](https://forums.unrealengine.com/t/tmap-access-elements-by-index/329947/2 "2015-08-26T11:22:24Z")

</div>

Convert keys/values to an array and you will be able to access them with index.

> **[TMap](https://docs.unrealengine.com/4.27/zh-CN/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/TMap/)**
>
> TMap主要由两个类型定义（一个键类型和一个值类型），以关联对的形式存储在映射中。

GenerateKeyArray and GenerateValueArray keywords.

---

<div class="post-metadata">

**Author:** ![\_NL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_NL](https://forums.unrealengine.com/u/_NL)\
**Post date:** [May 13, 2021, 3:35pm UTC](https://forums.unrealengine.com/t/tmap-access-elements-by-index/329947/4 "2021-05-13T15:35:16Z")

</div>

You probably meant to use the GenerateKeyArray() function. GenerateValueArray() as used in your example would output an array of floats instead.
