title: Looping over arrays, printing both index and value
body: <p>I want to do something like this:</p>
  
  <pre><code>foo=( )
  foo[0]="bar"
  foo[35]="baz"
  for((i=0;i&lt;${#foo[@]};i++))
  do
      echo "$i: ${foo[$i]}"
  done
  # Output:
  # 0: bar
  # 1: 
  </code></pre>
  
  <p>Then i tried to loop through it using for in:</p>
  
  <pre><code>foo=( )
  foo[0]="bar"
  foo[35]="baz"
  for i in ${foo[@]}
  do
      echo "?: $i"
  done
  # Output:
  # ?: bar
  # ?: naz
  </code></pre>
  
  <p>but here I don't know the index value.</p>
  
  <p>I know you could something like</p>
  
  <pre><code>foo=( )
  foo[0]="bar"
  foo[35]="baz"
  declare -p foo
  # Output:
  # declare -a foo='([0]="bar" [35]="baz")'
  </code></pre>
  
  <p>but, can't you do it in another way?</p>