Created
January 21, 2016 20:46
-
-
Save kopasetik/c8aea48180b50b7b003a to your computer and use it in GitHub Desktop.
Javascript JSON destructuring
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
| const request = require('request') | |
| const isMovie = (item) => { | |
| if (item.Type === "movie") return true | |
| return false | |
| } | |
| const movies = request('http://omdbapi.com/?s=highlander', | |
| ((err, res, body) => { | |
| if (!err && res.statusCode == 200) | |
| for (var {Title, Year} of JSON.parse(body)['Search'].filter(isMovie)){ | |
| console.log(Title + ' \(' + Year + '\)'); | |
| } | |
| })) | |
| //=> Highlander (1986) | |
| //=> Highlander II: The Quickening (1991) | |
| //=> Highlander: Endgame (2000) | |
| //=> Highlander: The Final Dimension (1994) | |
| //=> Highlander: The Source (2007) | |
| //=> Highlander: The Search for Vengeance (2007) | |
| //=> Highlander: The Adventure Begins (1994) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment