ReferenceError: multipleCartProductArray is not defined

I am trying to debug the following code in Firebug. I keep on getting an error of:

multipleCartProductArray
ReferenceError: multipleCartProductArray is not defined

If i remove the “var” from before the array declaration i.e. multipleCartProductArray = new Array(); the error does not appear anymore. I thought i was declaring an array correctly? Anyone know whats going on here?

Thanks!

<script>			
		$(function() {
			
			var cartProductObject = new Array();
			cartProductObject = <?php echo $jsonProductsObject; ?>;
			
			var multipleCartProductArray = new Array();
			$.each(cartProductObject, function(cartProductKey, cartProductValues) {
				multipleCartProductArray[cartProductKey] = parseInt(cartProductValues['product_quantity']);
			});
				
			$.each(cartProductObject, function(cartProductKey, cartProductValues) {
				$('#productDate' + cartProductKey + '-' + multipleCartProductArray[cartProductKey]).on('change', function(){
					checkValMatchString($(this), '<?php echo $this->_data['text']['selectDates_dropdownMenuTitle']; ?>', '.productDateError' + cartProductKey + '-' + multipleCartProductArray[cartProductKey], '<?php echo $this->_data['text']['systemError_requiredField']; ?>');
				});
			});

		});
	</script>

If removing var makes it work, then this is very likely a scoping issue (because removing var makes a variable global). But the code you posted looks fine as far as I can tell. It would be helpful if we could reproduce the issue. Can you send us a link to your page? Or post a JSFiddle that produces the error?