简体   繁体   中英

Is there a test to see if an Object is an associative Array?

Is there a test to see if an Object is an associative array?

Thanks.

When using an Object as an associative array, you are simply adding dynamic properties to it, with arbitrary values.

for...in loops iterate over only dynamic properties of an Object, so if you create a for...in loop and it completes one loop, you will know that the Object is an associative array.

http://livedocs.adobe.com/flex/3/langref/statements.html#for..in

function isObjectAssociativeArray(obj:Object):Boolean
{
    for (var prop in obj)
    {
        return true;
    } 
    return false;
}

You can try getQualifiedClassName and see if the return type is "Object". I haven't tested this myself, but it accepts flash primitives (Object, Array, String...) as well as Classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM