Pregunta

I'm creating text files like this:

Coffescript:

file = for post in posts
      "#{post.title}\n\n#{post.content}\n\n"

Javascrit:

file = (function() {
  var _i, _len, _results;
  _results = [];
  for (_i = 0, _len = posts.length; _i < _len; _i++) {
    post = posts[_i];
    _results.push("" + post.title + "\n\n" + post.content + "\n\n");
  }
  return _results;
})();

Outputs something like this:

["Chapter 1↵↵<p>As I made my way uphill, I understoo… of the woods, and continued my way uphill.</p>↵↵", "Chapter 2↵↵<p>I hadn't seen An-Mei for nearly six …pths of my heart, waiting to be awoken.</p><br>↵↵", "Chapter 3↵↵<p>"Sure they allow visitors?" I asked …ht?”</p><p>She gave her head another shake.</p>↵↵", "Chapter 4↵↵<p>Back in the hotel, I thought about w…leading the way—we ventured into the woods.</p>↵↵", "Notes↵↵<p>- Search places where only one word can be used &nbsp;</p>↵↵", "Experiment↵↵<p>There was no one in the streets. I … realized it was a fireplace.&nbsp;</p><p>"</p>↵↵", "Untitled↵↵↵↵"]

Now I want to turn the text file into an HTML document instead so I want to modify file to output something like this:

["<html>...", "Chapter 1↵↵<p>As I made my way uphill...]

Perhaps doing something like this:

file.attachHeader
file.attachFooter

What the easiest way to do this (in CoffeScript, JS, or Underscore.js)?

¿Fue útil?

Solución

You can use push and unshift.

    var a=["b","c"];
    a.push("d");
    a.unshift("a");
    alert(a);

Example

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top