JavaScript array.push() doesn't seem to work

So, I’m trying to make an array for enemies in my small game, but Unity doesn’t like array.push().

Here’s the code:

#pragma strict

var Health : float = 100;
var positionX : int;
var positionY : int = 1;
var positionZ : int;
var enemyArray = [];
var enemyArrayLength : int = 10;

function Update()
{
	//Destroy(gameObject);
	for(var i : int = 0; i < enemyArrayLength; i++){
	enemyArray.push(enemyCreate());
	Debug.Log("i spawn an enemy");
	}	
}

function ApplyDamage (PlayerDamage : int)
{
	Health -= PlayerDamage;
	
	if(Health <= 0)
	{
		Destroy(gameObject);
		//enemyArray.pop();
	}
}

function enemyCreate() 
{
	coordMaker();
	var enemy = Instantiate(gameObject, Vector3(positionX, positionY, positionZ), transform.rotation);
}

function coordMaker()
{
	var random : int = (Random.Range(1,3));
	if(random==1)
	{
	positionX = transform.position.x + Random.Range(1, 6);
	positionY = transform.position.y;
	positionZ = transform.position.z + Random.Range(1, 6);
	Health = 100;
	}
	else
	{
	positionX = transform.position.x - Random.Range(1, 6);
	positionY = transform.position.y;
	positionZ = transform.position.z - Random.Range(1, 6);
	Health = 100;
	}	
}

Please help, guys, I don’t know who to ask!

You’re using a built in array when you’re doing this:

var enemyArray = [];

Those are .NET arrays, and can’t be resized, so they lack the .push method. Replace it with a “JavaScript Array”:

var enemyArray = new Array();

You also need to actually return an object from the enemyCreate method, otherwise things will go poorly:

function enemyCreate() 
{
    coordMaker();
    var enemy = Instantiate(gameObject, Vector3(positionX, positionY, positionZ), transform.rotation);
    return enemy;
}

I’d suggest reading up on the two different array types here. Remember, Unity’s “JavaScript” is NOT JavaScript. It’s C# dressed up to look like JavaScript.