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

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

something like this:


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



	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)


	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