开发者

How to create multiple arrays from 2? (actionscript, flash)

开发者 https://www.devze.com 2022-12-28 21:30 出处:网络
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)

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 corres开发者_如何学Gopond to param B should appear in ArrayB.

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


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}
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号