Skip to content

Instantly share code, notes, and snippets.

@DavidMellul
Last active March 13, 2018 23:33
Show Gist options
  • Select an option

  • Save DavidMellul/2286bcc1eaa86206afeca496c047760d to your computer and use it in GitHub Desktop.

Select an option

Save DavidMellul/2286bcc1eaa86206afeca496c047760d to your computer and use it in GitHub Desktop.
// A dead-easy data structure representing a database
let ArticlesDatabase = {
articles: [
{
'id': 1,
'title': 'Insane prank, I broke my leg watch this'
},
{
'id': 2,
'title': 'Cops arrested me, discover why'
},
{
'id': 3,
'title': 'Look at this, the second is unbelievable'
}
],
getArticles: function() { return this.articles },
addArticle: function(article) { this.articles.push(article); }
};
// Let's use our database
console.log(ArticlesDatabase.getArticles());
// => Exactly what you expected, the array with the 3 objects
ArticlesDatabase.addArticle(
{
'id':4,
'title': 'Nice one !'
});
console.log(ArticlesDatabase.getArticles());
// => The array with 4 objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment