Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要一些帮助来搜索我的数组。我创建了一个冒泡排序过滤器,现在我需要一些帮助来搜索其中的某些值。
例如,我的数组包含数字“1,4,5,7,8,5,5,4,3,2”,我想看看数组中有多少个五。
我该如何解决这个问题?
计算特定值的出现次数就像遍历整个数组并在找到该值后立即递增变量一样简单。
var myArray:Array = [1, 4, 5, 7, 8, 5, 5, 4, 3, 2]; var counter:int = 0; for (var a:int = 0; a < myArray.length; a++) { if (myArray[a] == 5) { counter++; } } trace("occurences of 5: " + counter);