-1

I need some help with searching my array. I've created a bubble sorting filter and now I need some help with searching for certain values within it.

For example my array contains the numbers "1,4,5,7,8,5,5,4,3,2" and I want to see how many fives there are in the array.

How do I solve this problem?

Gunnar
  • 1
  • Please @ all : try to post a comment when You downvote a question or an answer. this may help new members to improve their posts on this community. thx. Nicolas – tatactic Feb 22 '19 at 14:44

1 Answers1

1

Counting the occurences of a specific value is as simply as iterating over the whole array and incrementing a variable as soon as it finds that value.

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);
obscure
  • 11,916
  • 2
  • 17
  • 36