# Arrays and date

**URL:** <https://forum.kirupa.com/t/arrays-and-date/263717>\
**Category:** Uncategorized\
**Created:** [June 18, 2008, 4:11pm UTC](https://forum.kirupa.com/t/arrays-and-date/263717 "2008-06-18T16:11:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zero\_j](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zero\_j](https://forum.kirupa.com/u/zero_j)\
**Post date:** [June 18, 2008, 4:11pm UTC](https://forum.kirupa.com/t/arrays-and-date/263717/1 "2008-06-18T16:11:46Z")

</div>

Hi there,

I am pretty new with Actionscript (on the border of stupidity ;))I wonder if you guys can help.

I am trying to display items on a array depending on certain date of the month ( july 1st: text1, july 2nd: text 2, etc, etc.)

Now, this is my actual code:

var currentDate:Date = new Date();  
var indexPosition = currentDate.getDate();  
var textForToday = julyArr[indexPosition];

var julyArr:Array = new Array();

julyArr[0] = “Text for the 1st of July”;  
julyArr[1] = “Text for the 1st of July”;  
julyArr[2] = “Text for the 2nd of July”;  
julyArr[3] = “Text for the 3rd of July”;

date\_txt.text=textForToday;

But when I test my movie it returns undefined

Any clues???

Thank guys.

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 18, 2008, 7:29pm UTC](https://forum.kirupa.com/t/arrays-and-date/263717/2 "2008-06-18T19:29:13Z")

</div>

You’re calling the indexPosition for julyArr before you’ve created the array. That’s why it’s undefined.

It will also return an undefined value for any date that’s greater than 3 unless you add more elements to the array.

Finally, you might want to change it slightly so that indexPosition is currentDate.getDate()-1; to avoid having to duplicate the first two elements of your array. Try this:

```auto
// create array
var julyArr:Array = new Array();
julyArr[0] = "Text for the 1st of July";
julyArr[1] = "Text for the 2nd of July";
julyArr[2] = "Text for the 3rd of July";
julyArr[3] = "Text for the 4th of July";
// continue to julyArr[30] = "Text for the 31st of July";
julyArr[30] = "Text for the 31st of July";
// retrieve current date
var currentDate:Date = new Date();
// set index position == date - 1
var indexPosition = currentDate.getDate()-1;
// assign date element of array to date_txt
var textForToday = julyArr[indexPosition];
date_txt.text=textForToday;

```

---

<div class="post-metadata">

**Author:** ![zero\_j](https://avatars.discourse-cdn.com/v4/letter/z/9de053/32.png) [@zero\_j](https://forum.kirupa.com/u/zero_j)\
**Post date:** [June 19, 2008, 8:22am UTC](https://forum.kirupa.com/t/arrays-and-date/263717/3 "2008-06-19T08:22:06Z")

</div>

[glosrfc](http://www.kirupa.com/forum/member.php?u=33826),

It worked beautifuly, thank you sooooo much for your help.
