dimanche 29 novembre 2015

Actionscript, hasOwnProperty() of multidimensional arrays

I'm trying to check wether a key exists in a multidimensional array. The following code is my example:

var tiles:Array = new Array(
                    new Array(4),
                    new Array(4),
                    new Array(4),
                    new Array(4)
                 );
if(test.hasOwnProperty(2)) {
  trace('True');
} else {
  trace('False');

This returns True, as expected since the key 2 indeed exists in the array "test".

However if I try to this on any of the arrays within my array, the code always returns False.

var tiles:Array = new Array(
                    new Array(4),
                    new Array(4),
                    new Array(4),
                    new Array(4)
                 );
if(test[1].hasOwnProperty(2)) {
  trace('True');
} else {
  trace('False');

I was hoping anyone could shed some light on this, what am I missing? Maybe there is another way of doing this check? Any help is much appreciated, thanks! :)

Aucun commentaire:

Enregistrer un commentaire