Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionscript object number of properties

How can I get the number of properties in a generic Actionscript Object? (Like Array length)

like image 509
Fragsworth Avatar asked Jan 15 '11 03:01

Fragsworth


1 Answers

You will have to loop over all element to count them:

function objectLength(myObject:Object):int {
 var cnt:int=0;

 for (var s:String in myObject) cnt++;

 return cnt;
}

var o:Object={foo:"hello", bar:"world"};
trace(objectLength(o)); // output 2
like image 124
Patrick Avatar answered Oct 19 '22 09:10

Patrick