Last active
March 13, 2018 23:33
-
-
Save DavidMellul/606e8ad6f2f1d377ae930e36f3600b90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A dead-easy data structure representing a database | |
| let ArticlesDatabase = { | |
| content: [ | |
| { | |
| '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' | |
| } | |
| ], | |
| getAll: function() { return this.content }, | |
| add: function(article) { this.content.push(article); } | |
| }; | |
| // Let's use our database | |
| console.log(ArticlesDatabase.getAll()); | |
| // => Exactly what you expected, the array with the 3 objects | |
| ArticlesDatabase.add( | |
| { | |
| 'id':4, | |
| 'title': 'Nice one !' | |
| }); | |
| console.log(ArticlesDatabase.getAll()); | |
| // => The array with 4 objects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment