Skip to content

Instantly share code, notes, and snippets.

@wholypantalones
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save wholypantalones/a620ae9aa189fcde9289 to your computer and use it in GitHub Desktop.

Select an option

Save wholypantalones/a620ae9aa189fcde9289 to your computer and use it in GitHub Desktop.
Angular find index of variable
/* usage:
$scope.thing = $scope.myObject.thing2[$scope.findIndex($scope.myObject.thing2,'attr',$scope.variable)];
> $scope.thing = $scope.myObject.thing2[i];
*/
$scope.findIndex = function(arr,attr,val) {
for (var i = 0; i < arr.length; i += 1) {
if (arr[i][attr] === val) {
return i;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment