0

I have an array of paired values

1:9,10:8,20:7

representing quantities and prices/price breaks which I want to iterate through to establish the correct price point to use when a particular quantity is ordered.

var qty = parseFloat($("#qtyInput").val());
var price_array = $("#sku_price_array" + sel_class).val();
var sku_price_array = price_array.split(",");
for (var i=0; i<sku_price_array.length; i++) {
    var sku_prices = sku_price_array[i].split(":");
    if (qty > sku_prices[i][0]) {
        alert(sku_prices[i][1]);
    };
};

My alert is not showing the values I intended.

What I'm aiming for is getting the value 1 for sku_prices[i][0] on the first run through, and alerting the value 9 from sku_prices[i][1].

On my first run-through, firebug shows my sku_prices[i][0] value to be 1, but the alert is undefined.

(edit:escape characters removed, thank you)

3
  • If your array really is like in your example, you have an error message in the console... Or is it actually a string? Commented Jul 15, 2013 at 20:22
  • 1
    why do you have escape sequences for the quotes in split? It could be causing your error Commented Jul 15, 2013 at 20:22
  • sku_prices isn't a double array Commented Jul 15, 2013 at 20:26

1 Answer 1

2

sku_prices isn't a two-dimensional array. Omit the [i] and it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. That was the ticket. I appreciate your help!
@user2187710 sure thing. Also, as far as I can tell, the semicolons after your if and for blocks don't do anything. You can remove them if you want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.