我有一个数组:
var exArr:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
我想要数组:
var resultArr:Array = [5,6,7,8,9,10,11,12,13,14];
答案 0 :(得分:1)
这可能会对你充分使用。
var a:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
a.sort();
var i:int = 0;
while(i < a.length) {
while(i < a.length+1 && a[i] == a[i+1]) {
a.splice(i, 1);
}
i++;
}
其他,see here
答案 1 :(得分:1)
试试这个:
var exArr:Array = [5,6,10,6,5,11,7,9,12,8,8,13,7,9,14];
function group(subject:Array):Array
{
var base:Array = subject.slice().sort(Array.NUMERIC);
var prev:Number = base[0];
for(var i:int = 1; i < base.length; i++)
{
if(base[i] === prev)
{
base.splice(i, 1);
i--;
}
prev = base[i];
}
return base;
}
trace( group(exArr) );