title: implement vlookup like function in javascript
body: <p>I have an object in my React component's state that looks like this:</p>
  
  <pre><code>const elementPositions =  {
    "0": 180.2,
    "1": 350.8666666666667,
    "2": 521.5333333333333,
    "3": 692.2,
    "4": 862.8666666666667,
    "5": 1033.5333333333333,
    "6": 1204.2
  }
  </code></pre>
  
  <p>I have scroll listener that returns a scroll position value, let's say <code>const scrollY = 466</code> in this instance.</p>
  
  <p>I need to create a function that returns the corresponding index for the scroll position - i.e. <code>466</code> would return 1 since it is greater than <code>350</code> but less than <code>521</code>. What's the best way to achieve this? I was thinking something along the lines of this but am not sure it's the best approach:</p>
  
  <pre><code>const values = Object.values(elementPositions)
  values.push(scrollY)
  values.sort((a, b) =&gt; {return a-b})
  const newIndex = values.indexOf(scrollY) - 1 
  </code></pre>