Skip to content

Instantly share code, notes, and snippets.

@imbdb
Created November 8, 2016 13:37
Show Gist options
  • Save imbdb/4e1697a96911d180e6e3ce821a8b65a8 to your computer and use it in GitHub Desktop.
Save imbdb/4e1697a96911d180e6e3ce821a8b65a8 to your computer and use it in GitHub Desktop.
JS function to get index of json object in array
//Usage
//jsonSearch(jsonArray,{'key':'value})
var jsonSearch = function(json_array,needle){
return json_array.map(function(d) { return d[Object.keys(needle)[0]]; }).indexOf(needle[Object.keys(needle)[0]])
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment