# Array problems

**URL:** <https://forum.kirupa.com/t/array-problems/265639>\
**Category:** Uncategorized\
**Created:** [July 10, 2008, 10:34pm UTC](https://forum.kirupa.com/t/array-problems/265639 "2008-07-10T22:34:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![juskin](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@juskin](https://forum.kirupa.com/u/juskin)\
**Post date:** [July 10, 2008, 10:34pm UTC](https://forum.kirupa.com/t/array-problems/265639/1 "2008-07-10T22:34:04Z")

</div>

this is actually a condensed and more exact problem im having,  
I want to loop thru this array, and return the lexUrl value to  
the targetURL, based on the currentImage value. right now im  
doing if statements which I thought would work but it just keeps  
coming out the array index [8] value. how would I construct a loop  
that would do that??

var lexUrl:Array = new Array();  
lexUrl[0] = “[http://www.lexus.com/lexus-main/models/LS/](http://www.lexus.com/lexus-main/models/LS/)”;  
lexUrl[1] = “[http://www.lexus.com/lexus-main/models/GS/](http://www.lexus.com/lexus-main/models/GS/)”;  
lexUrl[2] = “[http://www.lexus.com/lexus-main/models/ES/](http://www.lexus.com/lexus-main/models/ES/)”;  
lexUrl[3] = “[http://www.lexus.com/lexus-main/models/IS/](http://www.lexus.com/lexus-main/models/IS/)”;  
lexUrl[4] = “[http://www.lexus.com/lexus-main/models/ISf/](http://www.lexus.com/lexus-main/models/ISf/)”;  
lexUrl[5] = “[http://www.lexus.com/lexus-main/models/SC/](http://www.lexus.com/lexus-main/models/SC/)”;  
lexUrl[6] = “[http://www.lexus.com/lexus-main/models/LX/](http://www.lexus.com/lexus-main/models/LX/)”;  
lexUrl[7] = “[http://www.lexus.com/lexus-main/models/GX/](http://www.lexus.com/lexus-main/models/GX/)”;  
lexUrl[8] = “[http://www.lexus.com/lexus-main/models/RX/](http://www.lexus.com/lexus-main/models/RX/)”;

currentImage = eventObject.data.number;

if (currentImage = 1) {  
targetURL=lexUrl[0];  
}  
if (currentImage = 2) {  
targetURL=lexUrl[1];  
}  
if (currentImage = 3) {  
targetURL=lexUrl[2];  
}  
if (currentImage = 4) {  
targetURL=lexUrl[3];  
}  
if (currentImage = 5) {  
targetURL=lexUrl[4];  
}  
if (currentImage = 6) {  
targetURL=lexUrl[5];  
}  
if (currentImage = 7) {  
targetURL=lexUrl[6];  
}  
if (currentImage = 8) {  
targetURL=lexUrl[7];  
}  
if (currentImage = 9) {  
targetURL=lexUrl[8];  
}

infoBtn.onRelease = function() {  
getURL(targetURL, “\_blank”);  
}

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [July 11, 2008, 5:52am UTC](https://forum.kirupa.com/t/array-problems/265639/2 "2008-07-11T05:52:23Z")

</div>

> **[Infrequently Asked Questions and Other Interesting Threads](https://www.kirupa.com/forum/showthread.php?229727-Infrequently-Asked-Questions-and-Other-Interesting-Threads&s=dd061abc84a2c75887c8337f87a07437&p=1923634#post1923634)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

You could also shorten your code to this:

```auto
var lexUrl:Array = new Array();
lexUrl[0] = "http://www.lexus.com/lexus-main/models/LS/";
lexUrl[1] = "http://www.lexus.com/lexus-main/models/GS/";
lexUrl[2] = "http://www.lexus.com/lexus-main/models/ES/";
lexUrl[3] = "http://www.lexus.com/lexus-main/models/IS/";
lexUrl[4] = "http://www.lexus.com/lexus-main/models/ISf/";
lexUrl[5] = "http://www.lexus.com/lexus-main/models/SC/";
lexUrl[6] = "http://www.lexus.com/lexus-main/models/LX/";
lexUrl[7] = "http://www.lexus.com/lexus-main/models/GX/";
lexUrl[8] = "http://www.lexus.com/lexus-main/models/RX/";

currentImage = eventObject.data.number;
targetURL = lexUrl[currentImage - 1];

infoBtn.onRelease = function() {
	getURL(targetURL, "_blank");
};

```
