0

I've created a multidimensional array in javascript, but I need to convert to coffeescript. The multidimensional array works fine in javascript but doesn't seem to work properly when I convert using JS2coffee and I can't seem to find any solution online.

Here is my relevant code:

selectedCheck = [
  check_11_50
  check_11_250
  check_11_500
  check_11_1000
  check_11_2000
]
check_11_50 = [
  50
  69.99
  250
  169.99
  "1785-00050/check-11"
]
check_11_250 = [
  250
  169.99
  500
  230.99
  "1785-00250/check-11"
]
# ...

This should print "250".

console.log selectedCheck[1][0]
3
  • 1
    Side Note: You don't "call" arrays (or variables), you "use" them. You "call" functions. Commented Dec 15, 2014 at 17:34
  • Unrelated, but... I'd strongly recommend not using positions when you have object available to you. Using positions is brittle. Of course, if you're not in control of the data you're consuming, it doesn't matter. Commented Dec 15, 2014 at 17:36
  • That's not a multi-dimensional array, that's an array of arrays. They're not the same thing. Commented Dec 15, 2014 at 17:54

1 Answer 1

3

You need to define check_11_50 and such before selectedCheck, as you're overwriting their values later:

check_11_50 = [
  50
  69.99
  250
  169.99
  "1785-00050/check-11"
]
check_11_250 = [
  250
  169.99
  500
  230.99
  "1785-00250/check-11"
]
# ...and so on...
selectedCheck = [
  check_11_50
  check_11_250
  check_11_500
  check_11_1000
  check_11_2000
]

Or of course, just do it all together:

selectedCheck = [
  [
    50
    69.99
    250
    169.99
    "1785-00050/check-11"
  ]
  [
    250
    169.99
    500
    230.99
    "1785-00250/check-11"
  ]
  # ...and so on...
]
Sign up to request clarification or add additional context in comments.

1 Comment

Yep! When I did this I moved the defs around for clarity out of habit. sigh

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.