The “in” operator
2010 May 24
Juten Tach,
i work with Actionscript for some time now, but i wasn’t aware of that little thing. You can use “in” for checking, if an attribute/field exists in an object, like so:
package { import flash.display.Sprite; public class Test extends Sprite { public function Test() { var myObject:Object = {name: "foo", nothing: "bar"}; trace("name" in myObject); // true trace("anything" in myObject); // false } } }
It also works for checking for fields in class instances. Might come in handy sometime
2 Responses
leave one →

This is very helpful indeed, thx!
And this operator works much faster than Object.hasOwnProperty() method, which is created for the same purpose.