# Arrays question

**URL:** <https://forum.kirupa.com/t/arrays-question/16454>\
**Category:** Uncategorized\
**Created:** [March 25, 2003, 9:32am UTC](https://forum.kirupa.com/t/arrays-question/16454 "2003-03-25T09:32:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanley](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Stanley](https://forum.kirupa.com/u/Stanley)\
**Post date:** [March 25, 2003, 9:32am UTC](https://forum.kirupa.com/t/arrays-question/16454/1 "2003-03-25T09:32:10Z")

</div>

Arrays are kinda new to me,… but they seem great.  
Question:  
I made an array  
montharray = [“jan”,“feb”,“mar”,“april”,“may”,june",“juli”,…etc]  
–\> 12 months.

then I have a variable  
var month.

Suppose month == “feb”, then --\> month = 2 (the index value+1 of “feb” in my array).  
if month == “mar”, then the month-value changes to 3,  
etc…

how should I do this ?

thanks guys,  
Stanley :cowboy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 25, 2003, 10:08am UTC](https://forum.kirupa.com/t/arrays-question/16454/2 "2003-03-25T10:08:42Z")

</div>

if you’re array is set up correctly,

```auto

month=montharray[0];

```

would set month equal to “jan”;

if you’re asking how to retreive the number of the array stack, from the value, then you’d have to create a loop. maybe something like

```auto

function retMonthVal(month){
  for(i=0;i<montharray.length;i++){
    if(_root.montharray*==month){
      month=i;
      return(month);
    }
  }
}

```

that might be a little convoluted. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 25, 2003, 10:12am UTC](https://forum.kirupa.com/t/arrays-question/16454/3 "2003-03-25T10:12:12Z")

</div>

Howdy…

Something like this???

```auto
monthArray = new Array("jan", "feb", "mar",
				   "april", "may", "june",
				   "july", "aug", "sept",
				   "oct", "nov", "dec");

var month;

for (i = 0 ; i < monthArray.length ; i++)
{
	if (monthArray* == "mar")
		month = i + 1;
}
trace("month = " + month);

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 25, 2003, 10:19am UTC](https://forum.kirupa.com/t/arrays-question/16454/4 "2003-03-25T10:19:28Z")

</div>

I was just about getting there myself (figured the loop thing out :-)… and the result looks similar to what you guys have written.  
Thanks David and Cyanblue…great to see I’m getting the hang of this…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 25, 2003, 10:24am UTC](https://forum.kirupa.com/t/arrays-question/16454/5 "2003-03-25T10:24:44Z")

</div>

Say David…  
why do u use " return(month); " in your function ? Just wondering… i’ve never used ‘return’  
you’ve set month = i;  
Why add another line of code?

stanley

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 25, 2003, 10:55am UTC](https://forum.kirupa.com/t/arrays-question/16454/6 "2003-03-25T10:55:32Z")

</div>

mostly because I’m cold with Flash.

I figured that, though this function might not be what you were looking for specificaly, that it might give an indication of different things that can be done that you might not know of.  
To tell the truth, I have no clue if my script does what I was thinking it would do.  
ie  
month=3;  
call to function retMonthVal(month);  
the place where you were calling that from would now have month set to “april”.  
Like I said… I’m not even posative that it would do that. 🙂  
In general, return is used to send data back to whatever script was calling the funtion, to continue on it’s own objectives.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 25, 2003, 1:12pm UTC](https://forum.kirupa.com/t/arrays-question/16454/7 "2003-03-25T13:12:57Z")

</div>

It was exactly what i was looking for. I only used the for(…) loop part, without the function. And month needed to be i+1 (januari becomes 1, februari 2, etc…)

so thanks again  
stanley
