# Simple solution to setting array value or if no value, make it 0?

**URL:** <https://forum.kirupa.com/t/simple-solution-to-setting-array-value-or-if-no-value-make-it-0/284092>\
**Category:** Uncategorized\
**Created:** [March 15, 2009, 1:23am UTC](https://forum.kirupa.com/t/simple-solution-to-setting-array-value-or-if-no-value-make-it-0/284092 "2009-03-15T01:23:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarmanje](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jarmanje](https://forum.kirupa.com/u/jarmanje)\
**Post date:** [March 15, 2009, 1:23am UTC](https://forum.kirupa.com/t/simple-solution-to-setting-array-value-or-if-no-value-make-it-0/284092/1 "2009-03-15T01:23:07Z")

</div>

Hello there. I have an array which is filled up when someone clicks on a button.

something like this:

```auto

var ThumbArray:Array = new Array();

//on click, adds new value like this
ThumbArray[ThumbArray.length] = [productid.text, viewID.text, price.text]

```

I limit it to a maximum of 14 values.

I now need to know a good way to set a variable equal to the value of a row of the array - but if there is no value then it becomes “0”

So this is my code so far

```auto

	theVariables.varMat1 = ThumbArray[0][1];
	theVariables.varMat2 = ThumbArray[1][1];
	theVariables.varMat3 = ThumbArray[2][1];
	theVariables.varMat4 = ThumbArray[3][1];	
	theVariables.varMat5 = ThumbArray[4][1];	
	theVariables.varMat6 = ThumbArray[5][1];	
	theVariables.varMat7 = ThumbArray[6][1];	
	theVariables.varMat8 = ThumbArray[7][1];	
	theVariables.varMat9 = ThumbArray[8][1];	
	theVariables.varMat10 = ThumbArray[9][1];	
	theVariables.varMat11 = ThumbArray[10][1];
	theVariables.varMat12 = ThumbArray[11][1];	
	theVariables.varMat13 = ThumbArray[12][1];	
	theVariables.varMat14 = ThumbArray[13][1];	

```

I want to check if ThumbArray[0][12] (for example) exists. So if there are only 5 values ( thumbArray.length = 5 ) then i need to set theVariables.varMat6 -\> theVariables.varMat14 = 0

I hope you understand what i mean!!

I know i should be looping through using the thumbArray.length, but i cannot get my head around it!

this is how it would work… but is completely impractical to code like this! (but it works)

```auto

	if(ThumbArray.length==1) { 
	theVariables.varMat1 = ThumbArray[0][1];
	}
	
		if(ThumbArray.length==2) { 
	theVariables.varMat1 = ThumbArray[0][1];
	theVariables.varMat2 = ThumbArray[1][1];
	}

			if(ThumbArray.length==3) { 
	theVariables.varMat1 = ThumbArray[0][1];
	theVariables.varMat2 = ThumbArray[1][1];
		theVariables.varMat3 = ThumbArray[2][1];
	}
//etc etc

```
