# Find Number Of Same Elements In An TArray

**URL:** <https://forums.unrealengine.com/t/find-number-of-same-elements-in-an-tarray/452860>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 26, 2019, 10:00am UTC](https://forums.unrealengine.com/t/find-number-of-same-elements-in-an-tarray/452860 "2019-07-26T10:00:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TAN](https://forums.unrealengine.com/u/TAN)\
**Post date:** [July 26, 2019, 10:00am UTC](https://forums.unrealengine.com/t/find-number-of-same-elements-in-an-tarray/452860/1 "2019-07-26T10:00:10Z")

</div>

Hey all.  
I want to find how many of a some certain element in an array: (I have an inventory system and want to find how many of a same item in the inventory)  
How to do that ? I looked at docs but couldn’t find a function that returns number of specified same element. I thought there would be something like Array.FindNum() that already exists. Do I have to iterate or something similar ?  
Thanks.

---

<div class="post-metadata">

**Author:** ![IITheRealManII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IITheRealManII](https://forums.unrealengine.com/u/IITheRealManII)\
**Post date:** [July 26, 2019, 11:43am UTC](https://forums.unrealengine.com/t/find-number-of-same-elements-in-an-tarray/452860/2 "2019-07-26T11:43:22Z")

</div>

Hello,

You must create a function who return the number of items by class in yout inventory class like this:

```
Class::GetAmountByClass(TSubclassOf<class UObject> MyClassType)
 uint64 amount = 0;
{
    for( UItem* item: Items){
          if(item->getClass()==MyClassType)
          amount++;
     }
return amount;
}

```

Note: this is only a code sample.

You need to modify some things depending of your goals

---

<div class="post-metadata">

**Author:** ![TAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TAN](https://forums.unrealengine.com/u/TAN)\
**Post date:** [July 28, 2019, 9:06am UTC](https://forums.unrealengine.com/t/find-number-of-same-elements-in-an-tarray/452860/3 "2019-07-28T09:06:59Z")

</div>

Thanks. After looking at some other posts and comparing with yours I came up with below which works just fine.  
Thank you very much

```
	for (int i = 0; i < Inventory.Num() - 1; i++)
	{

		FInventoryItem CheckedSlot = Inventory[i];
		if (CheckedSlot == *EmptyInventorySlot)
		{
			AmountOfEmptySlots++;
		}
	}

```
