Skip to content

Instantly share code, notes, and snippets.

@kopasetik
Created January 21, 2016 20:46
Show Gist options
  • Save kopasetik/c8aea48180b50b7b003a to your computer and use it in GitHub Desktop.
Save kopasetik/c8aea48180b50b7b003a to your computer and use it in GitHub Desktop.
Javascript JSON destructuring
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