263 posts
  • Has been part of the Envato Community for over 6 years
  • Located in Antarctica
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+1 more
x360c says

How could I go about telling if a variable is an array or a string?

3868 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+9 more
flashjunkie says

var variablename:String = “blah”;

trace(typeof(variablename));

263 posts
  • Has been part of the Envato Community for over 6 years
  • Located in Antarctica
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+1 more
x360c says

Yeah, but that returns as an object when it’s an array. Null is also classified as an object so it’s conflicting. Any other methods?

263 posts
  • Has been part of the Envato Community for over 6 years
  • Located in Antarctica
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+1 more
x360c says

Any solutions?

755 posts
  • Has been part of the Envato Community for over 7 years
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+5 more
djankey says
var myString:String="djankey";
var myArray:Array=["djankey", "as-flash.com"];

Object.prototype.getTypeOf = function(obj){
    if (arguments.length) var my = obj;
    else var my = this;
    var t = ["Array","Boolean","Button","Color","Date","Function","LoadVars","MovieClip","Number","Object","Sound","String","TextField","TextFormat","XML","XMLSocket"];
    var i, l = t.length;
    for(i=0; i<l; i++) if (my.constructor == new [t[i]]().constructor) return t[i];
    return null;
}

trace(getTypeOf(myString));
trace(getTypeOf(myArray));

senocular: getTypeOf() – typeof alternative, recognizes more object types



266 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+5 more
JoeMC says

if (myVariable is Array){ trace(“true”); }

263 posts
  • Has been part of the Envato Community for over 6 years
  • Located in Antarctica
  • Has sold $100+ on Envato Market
  • Has collected 1+ items on Envato Market
+1 more
x360c says

Go Joe! Thanks man.

by
by
by
by
by
by