title: Add a curly brace to the first and last line of a text file using Node JS?
body: <p>I'm parsing and formatting a text file using the Node File System module which is then output into a newly formatted text file.  How can I add a { to the first line of text file and a } to the last line of the text file while retaining the formatting?</p>
  
  <p>I tried using array.unshift("{\n"); and array.push("}"); to add curly braces to the file but the console throws "array.unshift is not a function".</p>
  
  <pre><code>const fs = require('fs');
  
  const array = fs.readFileSync('input.txt').toString().split("\n");
  
  let result = '';
  
  for(let i = 0; i &lt; array.length; ++i){
      result += ( "\t\"" + (i + 1) + "\" : [ \"" + array[i] + "\" ], \n");
  };
  
  result.unshift("{\n");
  result.push("}");
  
  fs.writeFile("output.txt", result, function(err, data) {
    if (err) console.log(err);
    console.log("Successfully Written to File.");
  });
  </code></pre>
  
  <p>I expect output.text to read:</p>
  
  <pre><code>{
      "1" : [ "car" ],
      "2" : [ "train"],
  }
  </code></pre>
  
  <p>but the actual output is "result.unshift is not a function".</p>