Creating an array of records from search result
<p>I have been helping a friend improve on his code to create a record with the search result but instead of it creating an array of records it simply returns the last result. How do I get an array of records created? i.e. searching for in will create a record with:</p>

<p>title: Inheritance: Inheritance Cycle, Book 4
score: 2</p>

<p>title: The Sense of an Ending
score: 1</p>

<pre><code>books = [
  {
    title: "Inheritance: Inheritance Cycle, Book 4",
    author: "Christopher Paolini",
  },
  {
    title: "The Sense of an Ending",
    author: "Julian Barnes"
  },
  {
    title: "Snuff Discworld Novel 39",
    author: "Sir Terry Pratchett",
  }
]
search = prompt("Title?");

function count(books, pattern) {
  var result = [];
  var record = {};
  for (i = 0; i &lt; books.length; i++) {
    var index = -1;
    result[i] = 0;
    do {
      index = books[i].title.toLowerCase().indexOf(pattern.toLowerCase(), index + 1);
      if (index &gt;= 0) {
        result[i] = result[i] + 1;
        record.title = books[i].title;
        record.score = result[i];
      }
    } while (index &gt;= 0)
  }
  return record.title + " " + record.score;
}
alert(count(books, search));
</code></pre>
