title: REACT- Uncaught TypeError: Found non-callable @@iterator
body: <p>In react, I have a component that takes in 2 destructured parameters. One of them is an array called <code>points</code>. However, when attempting to call the <code>Math.max(...points)</code>, I get an error stating <code>Uncaught TypeError: Found non-callable @@iterator</code>. I am confused to this as <code>points</code> is definitely an array from where I am calling it. Below is the code where I get my error:</p>
  <pre><code>const MostVotesDisplay = ({anecdotes, points}) =&gt;
  {
    let max = Math.max(...points)
    if(max === 0)
      return (&lt;div&gt;No votes for any anecdotes yet!&lt;/div&gt;)
    else
      return (
        &lt;div&gt;
          &lt;p&gt;{anecdotes[max]}&lt;/p&gt;
          &lt;p&gt;{points[max]}&lt;/p&gt;
        &lt;/div&gt;
      )
  }
  </code></pre>
  <p>And the following code is where I call my function:</p>
  <pre><code>const [points, setPoints] = useState(Array(7).fill(0))
    return (
      &lt;div&gt;
        &lt;h1&gt;Anecdote of the day&lt;/h1&gt;
        &lt;p&gt;{anecdotes[selected]}&lt;/p&gt;
        &lt;p&gt;has {points[selected]} votes&lt;/p&gt;
        &lt;button onClick={() =&gt; vote(selected)}&gt;vote&lt;/button&gt;
        &lt;button onClick={generateAnecdote}&gt;next anecdote&lt;/button&gt;
  
        &lt;h1&gt;Anecdote with the most votes&lt;/h1&gt;
        &lt;MostVotesDisplay anecdotes={anecdotes} points={points}/&gt;
      &lt;/div&gt;
    )
  </code></pre>
  <p>I've included my full code for more information:</p>
  <pre><code>import React, {useState} from 'react'
  
  const MostVotesDisplay = ({anecdotes, points}) =&gt;
  {
    let max = Math.max(...points)
    if(max === 0)
      return (&lt;div&gt;No votes for any anecdotes yet!&lt;/div&gt;)
    else
      return (
        &lt;div&gt;
          &lt;p&gt;{anecdotes[max]}&lt;/p&gt;
          &lt;p&gt;{points[max]}&lt;/p&gt;
        &lt;/div&gt;
      )
  }
  const App = () =&gt; {
    const anecdotes = [
      'If it hurts, do it more often',
      'Adding manpower to a late software project makes it later!',
      'The first 90 percent of the code accounts for the first 10 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.',
      'Any fool can write code that a computer can understand. Good programmers write code that humans can understand.',
      'Premature optimization is the root of all evil.',
      'Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.',
      'Programming without an extremely heavy use of console.log is same as if a doctor would refuse to use x-rays or blood tests when diagnosing patients'
    ] 
    const [selected, setSelected] = useState(0)
  
    const [points, setPoints] = useState(Array(7).fill(0))
  
    const generateAnecdote = () =&gt; 
    {
      let index = Math.floor(Math.random() * anecdotes.length)
  
      setSelected(index)
    }
  
    const vote = (index) =&gt;
    {
      const newPoints = {...points}
      
      newPoints[index]++
  
      setPoints(newPoints)
    }
  
    return (
      &lt;div&gt;
        &lt;h1&gt;Anecdote of the day&lt;/h1&gt;
        &lt;p&gt;{anecdotes[selected]}&lt;/p&gt;
        &lt;p&gt;has {points[selected]} votes&lt;/p&gt;
        &lt;button onClick={() =&gt; vote(selected)}&gt;vote&lt;/button&gt;
        &lt;button onClick={generateAnecdote}&gt;next anecdote&lt;/button&gt;
  
        &lt;h1&gt;Anecdote with the most votes&lt;/h1&gt;
        &lt;MostVotesDisplay anecdotes={anecdotes} points={points}/&gt;
      &lt;/div&gt;
    )
  }
  
  export default App
  </code></pre>