I wonder about more short way to find that location of a numeric value between two array elements.
I have a value = 70, and I have an array array = [10, 30, 60, 100, 150]; I want to get trace result as “70 is between 60 and 100”. I get the result by coding given below. I wonder that are there any more simple way or any array function.
array = [10, 30, 60, 100, 150];
var value = 70;
for(var i=0; i< array.length;i++){
if(value >= array[i] && value < array[i+1]){
location = i;
}
}
trace(value + "is between" + array[location] + " and " + array[location+1];
Thanks