Skip to content
Advertisement

only use api/array data that meets a specific criteria

I have some api data, that is structured as follows

JavaScript

data i use atm to grab the lowest price:

JavaScript

Now i want 3 things with this data.

  1. grab the lowest price (i was able to do this, see code above)
  2. Grab the corresponding amount, for the row that has the lowest price (no idea if this is possible, or how to do this)
  3. if 2 is not possible, place a filter, saying something like: grab the lowest price, but only if amount is > 50?

any help is greatly appreciated

edit: if 2 or more things have the same “lowest price” for amounts: combining them, picking 1 of the 2, picking the first, or the highest amount would al be fine for this case. The chance this happens is very small with this data. so small that i am fine with not coding anything in for that situation because this will not cause issues for the result (if it works 99% of the time, it is good enough)

Advertisement

Answer

It’s pretty easy to do by iterating an array and grabbing an item that satisfies your conditions. Something like that.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement