0

I have the following data:

"books": [
   {
     "id": 1,
     "title": "Book title",
     "genre": "Novel"
   },
   {
     "id": 2,
     "title": "Book title two",
     "genre": "Novel"
   },
   {
     "id": 3,
     "title": "Book title three",
     "genre": "Horror"
   }
]

How can I get the title for a single book using a url parameter. i.e /?bookID=1

And is there a smart way to get a list of matches of genre, /?genre=Novel This should list all objects where genre=Novel.

Filip Blaauw
  • 731
  • 2
  • 16
  • 29
  • 1
    need some more context here - is this all in browser? or do you mean to make a request to server, and server-side filter of data? – hackerrdave Feb 11 '17 at 18:53
  • Using getJSON to load a json-file on the same server (no CORS needed). Should all be done in browser. – Filip Blaauw Feb 11 '17 at 18:55
  • 1
    There are many methods available to you on [`Array.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype). Start by reviewing the documentation. –  Feb 11 '17 at 19:04
  • Another possible answer for you: http://stackoverflow.com/questions/36039323/access-json-sub-levels-by-name – StudioTime Feb 11 '17 at 19:07
  • Damn, I answered the question but the question got closed before I could submit. See this [JSFiddle](https://jsfiddle.net/t6rr8u9s) for an example with just client side JS. – matt Feb 11 '17 at 19:10

0 Answers0