Javascript 2D arrays: null values and slicing

Been banging my ahead against JS 2D arrays for a day now. Every answer I look up seems to just lead to another error in a cyclical mess.

I just want a 2D int array initialized to 0. The below gives me an error: “NullReferenceException: A null value was found where an object instance was required” on houseGrid[x,z] = 0;. I’ve had slicing errors with various other attempts. I’m at my wits end. Help would be greatly appreciated!

#pragma strict

var floor : Transform;
var wall : Transform;

var houseSize : int = 50;
var minRoomSize : int = 5;
var maxRoomSize : int = 15;

function Start () {

	var x : int = 0;
	var z : int = 0;
	var i : int = 0;	
	var houseGrid : int[,];
	houseGrid = new int[houseSize,houseSize];
	for(z=0; z<houseSize; z++){
		for(x=0; x<houseSize; x++){
			houseGrid[x,z] = 0;

The code you posted here compiles and runs without errors. However, as to this:

I just want a 2D int array initialized to 0.

All you need is:

function Start () {
    var houseGrid = new int[houseSize, houseSize];

An int can’t be null, so an int[,] array always has every entry initialized to 0.