# How to use ForEachLoop to remove items from array?

**URL:** <https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106>\
**Category:** Audio\
**Tags:** foreachloop, unreal-engine, loop, Blueprint, question\
**Created:** [August 27, 2015, 2:49pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106 "2015-08-27T14:49:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TVinforest](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tvinforest/32/462613_2.png) [@TVinforest](https://forums.unrealengine.com/u/TVinforest)\
**Post date:** [August 27, 2015, 2:49pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/1 "2015-08-27T14:49:35Z")

</div>

![56040-howtoremove.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/8/d/f8dcc745e68244fd3a0b669517180f955ab7b492.jpeg)

Hello! For example of problem I created a simple Blueprint - I’m adding some elements to empty Cell\_Array and then try to remove them all. But 1/2 of elements are still in Cell\_Array after all. How to remove elements from Cell\_Array while iteration using only blueprint scripting? What is the usual solution?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Devero](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Devero](https://forums.unrealengine.com/u/Devero)\
**Post date:** [August 27, 2015, 3:00pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/2 "2015-08-27T15:00:23Z")

</div>

The problem is that as you remove items from the array, it shrinks some elements passed below your current index. You can create a ForLoop to go in reverse manually.

Hope that Helps =)

---

<div class="post-metadata">

**Author:** ![Devero](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Devero](https://forums.unrealengine.com/u/Devero)\
**Post date:** [August 27, 2015, 3:13pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/3 "2015-08-27T15:13:21Z")

</div>

Here is the Macro code to create your own “ForEachLoopReversed” =)

 ![56044-forloopreversed.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/8/0/880c8874364f39901d1d0f98828f57be5a94170a.jpeg)

---

<div class="post-metadata">

**Author:** ![TVinforest](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tvinforest/32/462613_2.png) [@TVinforest](https://forums.unrealengine.com/u/TVinforest)\
**Post date:** [August 27, 2015, 3:23pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/4 "2015-08-27T15:23:33Z")

</div>

![56063-re.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/3/c93037144e7358da4d721e576f92c281ae80bd7f.jpeg)

---

<div class="post-metadata">

**Author:** ![Oti](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Oti](https://forums.unrealengine.com/u/Oti)\
**Post date:** [August 27, 2015, 3:25pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/5 "2015-08-27T15:25:25Z")

</div>

Copy the array, now you have 2 identical arrays. Do foreach loop on either array and remove the coresponding index from the another array. Should work.

---

<div class="post-metadata">

**Author:** ![Barakka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Barakka](https://forums.unrealengine.com/u/Barakka)\
**Post date:** [January 8, 2018, 12:17am UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/6 "2018-01-08T00:17:29Z")

</div>

Great Job!

---

<div class="post-metadata">

**Author:** ![BitRot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bitrot/32/498776_2.png) [@BitRot](https://forums.unrealengine.com/u/BitRot)\
**Post date:** [June 28, 2022, 9:54pm UTC](https://forums.unrealengine.com/t/how-to-use-foreachloop-to-remove-items-from-array/330106/7 "2022-06-28T21:54:01Z")

</div>

For those stumbling upon this, note that there is now a Reverse For Loop already implemented for you. Joy!
