title: Array.reduce on a multidimensional array to array of objects
body: <p>In my poker app I have an array of hands, each hand being array of randomly selected card objects with value and suit:</p>
  
  <pre><code>[ [ { value: 5, suit: 's' },
      { value: 4, suit: 's' },
      { value: 6, suit: 'c' },
      { value: 11, suit: 'd' },
      { value: 12, suit: 'c' } ],
    [ { value: 9, suit: 'd' },
      { value: 12, suit: 'h' },
      { value: 8, suit: 'c' },
      { value: 12, suit: 's' },
      { value: 2, suit: 's' } ],
    [ { value: 4, suit: 'h' },
      { value: 6, suit: 's' },
      { value: 10, suit: 'c' },
      { value: 3, suit: 'd' },
      { value: 7, suit: 'd' } ] ]
  </code></pre>
  
  <p>To prepare the hands for evaluation I want to use Array.reduce to return an array of hand objects. So the output would be:</p>
  
  <pre><code>[ 
    { 
      values: [5, 4, 6, 11, 12],
      suits: ['s', 's', 'c', 'd', 'c'] 
    },      
    { 
      values: [9, 12, 8, 12, 2], 
      suits: ['d', 'h', 'c', 's', 's'] 
    },
    { 
      values: [4, 6, 10, 3, 7],
      suits: ['h', 's', 'c', 'd', 'd'] 
    } 
  ]
  </code></pre>
  
  <p>I tried implementing this with nested forEach's, but its failing and I don't know why. I have two console.log's within which output as expected, but in the end hands is identical to the input.</p>
  
  <pre><code>let temp = []
  hands.forEach((el) =&gt; {
    temp = el
    el = {}
    el.values = []
    el.suits = []
    console.log(el) //expected output
    temp.forEach((obj) =&gt; {
      el.values.push(obj.value)
      el.suits.push(obj.suit)
      console.log(el) //expected output
    })
  })
  console.log(hands) //same as original
  </code></pre>