views:

16

answers:

1

so I have array like ParamsArray

{a,b,a,a,...b} (so i have 2 kinds of parameters in this array - a and b) (here I have N strings)

and another array - DataArray

{data1,data2,...dataN} (different strings) (here I have N strings)

Now I created 2 new arrays ArrayA and ArrayB and I wanta want to feel arra ArrayA with all data (strings) from DataArray which correspond (by index in array) to a param in ParamsArray. and so strings that correspond to param B should appear in ArrayB.

How to do such thing in actionscript? (Please - I need a code example)

+1  A: 

I think this is what you want to do. Check http://livedocs.adobe.com/flex/3/langref/ and look at the array function. You can do a similar thing with Array.filter, and so on.

function foo(params:Array, data:Array):Object {
  var a:Array = [], b:Array = []
  data.forEach(function(item:*, index:int, array:Array):void {
    if(params[index] == "a") {
      a.push(item)
    } else if(params[index] == "b") {
      b.push(item)
    }
  })
  return {alist:a, blist:b}
} 
Glenn