# Array location between two element

**URL:** <https://forum.kirupa.com/t/array-location-between-two-element/637268>\
**Category:** Uncategorized\
**Created:** [October 6, 2017, 10:35am UTC](https://forum.kirupa.com/t/array-location-between-two-element/637268 "2017-10-06T10:35:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ekoneo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ekoneo/32/8893_2.png) [@ekoneo](https://forum.kirupa.com/u/ekoneo)\
**Post date:** [October 6, 2017, 10:35am UTC](https://forum.kirupa.com/t/array-location-between-two-element/637268/1 "2017-10-06T10:35:04Z")

</div>

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 😁

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [October 6, 2017, 3:02pm UTC](https://forum.kirupa.com/t/array-location-between-two-element/637268/2 "2017-10-06T15:02:21Z")

</div>

You could do this:

```auto
for(var i=0; i<array.length; i++){
 if(value < array[i]) break;
 location = i;
}

```

It will also stop looping once the position is found rather than keep going.
