Skip to content

Instantly share code, notes, and snippets.

@rxw1
Created April 9, 2014 10:34
Show Gist options
  • Save rxw1/10252749 to your computer and use it in GitHub Desktop.
Save rxw1/10252749 to your computer and use it in GitHub Desktop.
Find array index by object property
// find trip array index by trip id
var findById = function (source, trip_id) {
var length = source.length;
for (var i = length - 1; i >= 0; --i) {
if (source[i].trip_id === trip_id) {
return i;
}
}
throw "Couldn't find trip with id: " + trip_id;
};
@rxw1
Copy link
Author

rxw1 commented Apr 9, 2014

Better: $rootScope.trips.indexOf(trip).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment