Take the 2-minute tour ×

This should be pretty basic, but there aren't too many tutorials for ActionScript out there. JavaScript is close, but I can't find how to do this either. I want to be able to have a mixed array consisting of string and number data types, loop through the array and get the sum of the numbers while ignoring the strings.

Example Array:

var myArray:Array = [13, 10, "blah", 5, "eh", 10, "Twenty", "Thirty"];
share|improve this question
add comment

1 Answer

Something like the following should do the trick:

var total:Number = 0.0;
    if(myArray[i] is Number)
        total += myArray[i];
share|improve this answer
Yep, that was it. I had everything correct but the if statement. Thanks! –  mantonio Apr 9 '13 at 14:56
You're welcome. –  Barış Uşaklı Apr 9 '13 at 15:24
add comment

Your Answer


