Skip to content
Advertisement

Get a value from a multidimensional array

I have a multidimensional array as follows:

JavaScript

In my form the user would input a weight. What I am trying to do is if the weight is equal to or below the number in the weight part of the array that the corresponding rate is assigned to a variable.

Am stuck on how to do this. Any push in the right direction is appreciated.

Advertisement

Answer

First of all i would suggest you use a Object instead of a 2d-Array:

JavaScript

Then you can itterate through the “Weight”-Array:

JavaScript
Advertisement