# How to sort by newest through random items from an array?

**URL:** <https://forums.unrealengine.com/t/how-to-sort-by-newest-through-random-items-from-an-array/273640>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE4-27, question\
**Created:** [January 20, 2022, 3:47am UTC](https://forums.unrealengine.com/t/how-to-sort-by-newest-through-random-items-from-an-array/273640 "2022-01-20T03:47:00Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![midgunner66](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/midgunner66/32/466711_2.png) [@midgunner66](https://forums.unrealengine.com/u/midgunner66)\
**Post date:** [January 23, 2022, 3:52am UTC](https://forums.unrealengine.com/t/how-to-sort-by-newest-through-random-items-from-an-array/273640/7 "2022-01-23T03:52:43Z")

</div>

Reposting my solution from another thread:

> [@How to sort a random DateTime array from oldest to newest?](https://forums.unrealengine.com/t/how-to-sort-a-random-datetime-array-from-oldest-to-newest/274128/9):
>
> you don’t need to sort anything because all saves are already going to be played in chronological order, so you’ll always know which is the most recent. Basically, the most recent save is just the one that was played last, and the one that was played last is the one that is being played currently (i.e. the one that the player picks).
> 
> So all you have to do is put the save that is being playing currently at the top of the array (index 0), and it’ll already be sorted.
> 
> > **Example (Newest to Oldest)**
> >
> > NewGame → Save0  
> > SaveArray = {Save0}
> > 
> > NewGame → Save1  
> > SaveArray = {Save1, Save0}
> > 
> > NewGame → Save2  
> > SaveArray = {Save2, Save1, Save0}
> > 
> > LoadGame → Save0  
> > SaveArray = {Save0, Save2, Save1}
> > 
> > NewGame-\> Save3  
> > Save Array = {Save3, Save0, Save2, Save1}
> > 
> > LoadGame → Save2  
> > SaveArray = {Save2, Save3, Save0, Save1}
> 
> And to have it oldest to newest, you would either (A) add them at the **end** of the array, or (B) read the array in reverse.

And a running example with nodes in this post:

> [@How to sort a random DateTime array from oldest to newest?](https://forums.unrealengine.com/t/how-to-sort-a-random-datetime-array-from-oldest-to-newest/274128/13):
>
> When adding a new save, you just add it to the beginning of the array (index 0): [image] And when loading a save, you move the save to the beginning of the array: Here’s what that looks like (displaying time only); notice how it always stays sorted: Also, you can see that the date isn’t even used, so this works without storing the date. All we are doing is moving the save that the player chooses to the top; the sorting happens naturally.

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-sort-by-newest-through-random-items-from-an-array/273640)._
