title: How to convert mysql row of data into a javascript array? Node.js app
body: <p>First, I'm a newbie. No doubt, I've made some simple errors.</p>
  <p>Using Node.js with MySQL Database, I'm building a basic web app that allows users to login.  Once they've logged in they will be brought to their profile page and are displayed results of a quiz they've done in the form of a bar chart.</p>
  <p>I want covert a row of mysql data into an array.</p>
  <pre><code>const mysql = require('mysql');
  const dbconfig = require('/config/database');
  const connection = mysql.createConnection(dbconfig.connection);
  connection.query('USE ' + dbconfig.database);
  
  // Create an array of scores for each category depedning on the user who's 
  // loggedin.
  
  var category1scoreQuery = 
  &quot;SELECT c1q1, c1q2, c1q3, c1q4, c1q5, c1q6, c1q7, c1q8 
  FROM nodejs_login.assessment_score 
  AS a JOIN users as u ON a.respondent_id = u.user_respondent_id 
  WHERE a.respondent_id = user.user_respondent_id;&quot;;
  
  connection.connect(function(err){
      if (err) throw err;
  
      connection.query(category1scoreQuery, function(err, result, fields) {
          if (err) throw err;
  
          Object.keys(result).forEach(function(key){
              var cat1Array = result[key];
  
    // want to return array e.g. [&quot;45/60&quot;, &quot;60/60&quot;, &quot;40/40&quot;,&quot;30/40&quot;,&quot;15/20&quot;, 
    // &quot;30/40&quot;, &quot;30/60&quot;, &quot;20/40&quot;];
  
               console.log(cat1Array);
          })
      })
  });
  
  // I want to convert it to an array to parse the array of strings into 
  // totalUserScore over maxCategoryScore
  
  var i;
  var userCategoryScore1 = 0;
  var maxCategoryScore = 0;
  
  for(i=0; i &lt; cat1Array.length;i++){
  
  var splitScore = cat1Array[i].split(&quot;/&quot;);
  console.log(splitScore);
  
  myQuestionScore = parseInt(splitScore[0], 10);
  userCategoryScore1 += myQuestionScore;
  console.log(userCategoryScore);
  
  maxQuestionScore = parseInt(splitScore[1]);
  maxCategoryScore = maxCategoryScore + maxQuestionScore;
  console.log(maxCategoryScore);
  }
  </code></pre>
  <p>This is what I am actually getting which doesn't allow me to loop through.</p>
  <blockquote>
  <p>RowDataPacket {</p>
  <p>c1q1: '15/60',</p>
  <p>c1q2: '15/60',</p>
  <p>c1q3: '10/40',</p>
  <p>c1q4: '10/40',</p>
  <p>c1q5: '5/20',</p>
  <p>c1q6: '10/40',</p>
  <p>c1q7: '15/60',</p>
  <p>c1q8: '10/40' }</p>
  </blockquote>