# Problem reversing an array's contents

**URL:** <https://forum.kirupa.com/t/problem-reversing-an-arrays-contents/232792>\
**Category:** Uncategorized\
**Created:** [July 17, 2007, 9:25pm UTC](https://forum.kirupa.com/t/problem-reversing-an-arrays-contents/232792 "2007-07-17T21:25:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincenz0](https://avatars.discourse-cdn.com/v4/letter/v/e9c0ed/32.png) [@Vincenz0](https://forum.kirupa.com/u/Vincenz0)\
**Post date:** [July 17, 2007, 9:25pm UTC](https://forum.kirupa.com/t/problem-reversing-an-arrays-contents/232792/1 "2007-07-17T21:25:18Z")

</div>

I seem to be having trouble reversing the contents of an array

this is the code:

```auto

stop();
// Attributes arrays
var nd:Array = new Array();
var ns:Array = new Array();
var sp:Array = new Array();
var idnum:Array = new Array();

// Load XML
var newsXML:XML = new XML();
newsXML.ignoreWhite = true;
newsXML.onLoad = function()
{
        trace("this " + this);
        var nodes:Array = this.firstChild.childNodes;
    trace("nodes: " + nodes);
    for(i=0;i < nodes.length; i++) 
        {
            idnum* = nodes*.attributes.id;
            trace("idnum*: " + idnum*);
            nd* = nodes*.attributes.date;
            trace("nd*: " + nd*);
            ns* = nodes*.attributes.story;
            trace("ns*: " + ns*);
            sp* = nodes*.attributes.spacer;
            trace("sp*: " + sp*);
        }
    // Display Text
    var stringCache:String;
    for(n=0; n < idnum.length; n++)
        {
            trace(idnum[n]);
            trace(nd[n]);
            trace(ns[n]);
            trace(sp[n]);
            theNews.text += nd[n] + "
" + ns[n] + "
" + sp[n] + "
" + "
";
        }
    theNews.text = stringCache;
    }
newsXML.load("updates/adNews.php");

```

i’ve tried changing the ‘for’ loops for both the ‘n’ and ‘i’ variables to decrement them and also tried idnum.reverse(); but i can;t get it to work.

It’s a news page so i’m basically trying to get the newest story(which is attached to the highest id number in the databse) to post first and then post the rest in descending order.

anyone have any suggestions?

thanks 🙂
