var arr:Array=[1,33,5,7,8,12,4]; trace(getIndex(9,arr)); function getIndex(currentValue:Number,arr:Array):int { var flag:Boolean=true; var firstMatchIndex:int; var num:int=arr.length; for (var i:int=0; i<num; i++) { if (currentValue<arr[i]) { if (flag) { flag=false; firstMatchIndex=i; } } } if (currentValue>arr[num-1]) { firstMatchIndex=num-1; } return firstMatchIndex; }