How to determine if an associative array has a key?

Soviut picture Soviut · Mar 29, 2009 · Viewed 19.6k times · Source

In ActionScript 3, is there any convenient way of determining if an associative array (dictionary) has a particular key?

I need to perform additional logic if the key is missing. I could catch the undefined property exception, but I'm hoping that can be my last resort.

Answer

Cotton picture Cotton · Mar 31, 2009
var card:Object = {name:"Tom"};

trace("age" in card);  //  return false 
trace("name" in card);  //  return true

Try this operator : "in"