# How to compare two elements in the same array

**URL:** <https://forums.unrealengine.com/t/how-to-compare-two-elements-in-the-same-array/444419>\
**Category:** Blueprint\
**Tags:** randomize-array, unreal-engine, editor, UE4, Blueprint, question\
**Created:** [March 1, 2019, 9:28pm UTC](https://forums.unrealengine.com/t/how-to-compare-two-elements-in-the-same-array/444419 "2019-03-01T21:28:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PerCat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/percat/32/479573_2.png) [@PerCat](https://forums.unrealengine.com/u/PerCat)\
**Post date:** [March 1, 2019, 9:28pm UTC](https://forums.unrealengine.com/t/how-to-compare-two-elements-in-the-same-array/444419/1 "2019-03-01T21:28:11Z")

</div>

When an npc is generated they have a random id and their last name added to a struct which is then put into an array. How do I check those values against each other?

Say its 310:Gray, 262:Covics, and 689:Gray, how would I then check those against each other?

Making sure that the last names either do or don’t match and if they do then I check to make sure the numbers don’t, then from their if they do or don’t act upon them.

Thanc

---

<div class="post-metadata">

**Author:** ![kevincvanhorn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kevincvanhorn](https://forums.unrealengine.com/u/kevincvanhorn)\
**Post date:** [March 1, 2019, 10:19pm UTC](https://forums.unrealengine.com/t/how-to-compare-two-elements-in-the-same-array/444419/2 "2019-03-01T22:19:25Z")

</div>

This isn’t amazingly efficient, but here is pseudo-code you can implement in blueprints: essentially have two loops and go through the array, checking against all other elements if any last names match with that one.

```
Loop from index i = 0 to ArrayLength - 1
          bHasRelatives = false
          Loop from index j = 0 to ArrayLength - 1
                if Array[i].LastName == Array[j].LastName AND i != j
                      "Last Names are Equal for element i and j"
                      bHasRelatives = true;
          if bHasRelatives == false
                 "Element i has no relatives"
```
