actionscript 3 - Group a multidimensional array by a particular value -
i have multidimensional array , trying group them according value of array properties.
i'm trying group them id, won't know id beforehand. so, it's not can put in loop , while < 7, because won't know 7 maximum value id value,
array ( [0] => array ( [name] => r8900 [type] => public [id] => 1 ) [1] => array ( [name] => r8944 [type] => public [id] => 1 ) [2] => array ( [name] => r8922 [type] => private [id] => 3 ) [3] => array ( [name] => r8816 [type] => private [id] => 3 ) [4] => array ( [name] => r7434 [type] => vip [id] => 7 ) )
what i'm hoping produce:
array ( [1] => array ( [0] => array ( [name] => r8900 [type] => public ) [1] => array ( [name] => r8944 [type] => public ) ) [3] => array ( [2] => array ( [name] => r8922 [type] => private ) [3] => array ( [name] => r8816 [type] => private ) ) [7] => array ( [4] => array ( [name] => r7434 [type] => vip ) ) )
something simple as:
var result:object = {}; each(var i:object in input) { if(!result.hasownproperty(i.id)) { result[i.id] = []; } result[i.id].push(i); delete i.id; }
Comments
Post a Comment