<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" fontSize="12">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var myArray:Array=new Array();
private var filteredArr:Array=new Array();
private var keys:Array =new Array();
private function init():void
{
myArray.push("wang");
myArray.push("wang");
myArray.push("yan");
myArray.push("wang");
myArray.push("xiaoxiaocainiao");
myArray.push("xiaoxiaocainiao");
myArray.push("xiaoxiaocainiao");
myArray.push("小小菜鸟");
myArray.push("小小菜鸟");
myArray.push("小小菜鸟");
yuan.dataProvider=myArray;
}
private function onclick(event:MouseEvent):void
{
keys=null;
keys= new Array();
filteredArr=myArray.filter(removedDuplicates);
mubiao.dataProvider=filteredArr;
}
private function removedDuplicates(item:*, idx:uint, arr:Array):Boolean {
if (keys.indexOf(arr[idx])!=-1) {
return false;
} else {
keys.push(arr[idx]);
return true;
}
}
//过滤数组中重复元素--结束
]]>
</mx:Script>
<mx:Button x="144" y="285" label="过滤" click="onclick(event)" fontSize="12"/>
<mx:List id="yuan" x="10" y="47" width="150" height="200"></mx:List>
<mx:List id="mubiao" x="177" y="47" width="150" height="200"></mx:List>
<mx:Label x="51" y="21" text="源数组" fontSize="12"/>
<mx:Label x="189" y="21" text="目标数组" fontSize="12"/>
</mx:Application>
去掉数组中的重复数据
最新推荐文章于 2024-03-12 17:36:45 发布