From aa0bb225270e9f75ca2352165b187465175a11e8 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 5 Mar 2009 01:03:06 +0000 Subject: [PATCH] Added keys() and values() to Array-ificate Object/Dictionary properties. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5679 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/ArrayUtil.as | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/as/com/threerings/util/ArrayUtil.as b/src/as/com/threerings/util/ArrayUtil.as index acafcc23c..79448115a 100644 --- a/src/as/com/threerings/util/ArrayUtil.as +++ b/src/as/com/threerings/util/ArrayUtil.as @@ -45,6 +45,32 @@ public class ArrayUtil return arr; } + /** + * Get an array containing the property keys of the specified object, in their + * natural iteration order. + */ + public static function keys (obj :Object) :Array + { + var arr :Array = []; + for (var k :* in obj) { // no "each": iterate over keys + arr.push(k); + } + return arr; + } + + /** + * Get an array containing the property values of the specified object, in their + * natural iteration order. + */ + public static function values (obj :Object) :Array + { + var arr :Array = []; + for each (var v :* in obj) { // "each" iterates over values + arr.push(v); + } + return arr; + } + /** * Creates a shallow copy of the array. *