title: How can I write an array to a file in nodejs and keep the square brackets?
body: <p>I want to write a matrix to a .js file. When I use console.log(matrix) everything is fine but when I write it to the file it comes out differently.</p>
  
  <pre><code>var fs = require("fs");
  var matrix = new Array(10);
  for(var i=0;i&lt;matrix.length;i++) matrix[i]=[];
  
  for (var i = 0; i &lt; 100 ; i++)
  { 
      var n = i%10;
      matrix[n].push(i);      
  }
  
  console.log(matrix);
  
  //write it as a js array and export it (can't get brackets to stay)
  fs.writeFile("./matrixtest.js", matrix, function(err) {
  if(err) {
          console.log(err);
    } 
    else {
      console.log("Output saved to /matrixtest.js.");
      }
  });     
  </code></pre>
  
  <p>So the console.log gives me [[0,10,20,30,...100],...,[1,11,21,31,...91]] and so on. But opening up matrixtest.js it's only this:</p>
  
  <pre><code>0,10,20,30,40,50...
  </code></pre>
  
  <p>All the numbers separated by commas with no brackets. How do I prevent it from converting to that format? Thank you.</p>