0

I am writing an algorithm that checks the answers of a puzzle using JavaScript. I have several arrays of similar names ex. col1, col2, col3. I would like to create a string variable and use it to find a matching array, where the string matches the name of the array. Any advice on how I can achieve this?

  • 3
    show your input array and a string – RomanPerekhrest Jul 07 '16 at 10:22
  • Use [json](http://www.json.org/) format – Anupam Jul 07 '16 at 10:23
  • @anu _"JSON is a lightweight data-interchange format"_ I may have missed it, but where is Marie-Clare asking for a data-interchange format? – Andreas Jul 07 '16 at 10:28
  • 1
    that [awnser](http://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable) could help you – Rene Jul 07 '16 at 10:28
  • @Andreas Well it was my assumption that OP must be loading the puzzles from some db and later verifying it. As the background of the problem is not stated I might be wrong, so just wanted to provide info just in case. Thanks for pointing it out. – Anupam Jul 07 '16 at 10:39
  • I Know this is incorrect but I have 9 arrays named col1-col9 i want to make an algorthim that will loop around each array consecutively.... something like this (except this is obviously wrong) : function check() { var type = col; for(i=1; i<10; i++) { var arrayName = type + i; for (arrayName[]) { } } } – Marie-Clare Murray Jul 07 '16 at 10:54
  • @Marie-ClareMurray How are you getting these arrays? From server as a response or are you creating it dynamically? – Anupam Jul 07 '16 at 11:13

0 Answers0