title: How to iterate through table in Lua?
body: <p>So, I have a table something along these lines:</p>
  
  <pre><code>arr =
  {
    apples = { 'a', "red", 5 },
    oranges = { 'o', "orange", 12 },
    pears = { 'p', "green", 7 }
  }
  </code></pre>
  
  <p>It doesn't seem like it's possible to access them based on their index, and the values themselves are tables, so I just made the first value of the nested table the index of it, so it now looks like this:</p>
  
  <pre><code>arr =
  {
    apples = { 0, 'a', "red", 5 },
    oranges = { 1, 'o', "orange", 12 },
    pears = { 2, 'p', "green", 7 }
  }
  </code></pre>
  
  <p>So, now any time I use one of these tables, I know what the index is, but still can't get to the table using the index, so I started to write a function that loops through them all, and check the indexes until it finds the right one. Then I realized... how can I loop through them if I can't already refer to them by their index? So, now I'm stuck. I really want to be able to type arr.apples vs arr[1] most of the time, but of course it's necessary to do both at times.</p>