Flash as3 如何删除数组中的重复项? [英] Flash as3 How do I remove duplicates in an array?

查看:25
本文介绍了Flash as3 如何删除数组中的重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 flash 中只有一个名称(字符串)数组,我想确保删除数组中的任何重复项,或者至少确保数组中每个重复出现的值只执行一次函数.

Hi I just have an array of names (strings) in flash, and I want to make sure that any duplicates from the array are removed, or at least that a function is performed only once per reocurring value in the array.

推荐答案

更多猫皮:

var a:Array = ["Tom", "John", "Susan", "Marie", "Tom", "John", "Tom", "Eva"];
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++;
}

这篇关于Flash as3 如何删除数组中的重复项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆