Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
(function() {
  var csv = [];
      csv.push('name,age,gender');
      csv.push('jake,13,m');
      csv.push('sarah,15,f');
      csv.push('john,18,m');
      csv.push('nick,13,m');
    
  console.log(csv);
    
  function jsonDataArray(array) {
    var headers = array[0].split(',');
    var jsonData = [];
    for ( var i = 1, length = array.length; i < length; i++ )
    {
      var row = array[i].split(',');
      var data = {};
      for ( var x = 0; x < row.length; x++ )
      {
        data[headers[x]] = row[x];
      }
      jsonData.push(data);
      
    }
    
    return jsonData;
  }
  
  console.log(jsonDataArray(csv));
    
   
})();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers