Javascript 如何在ANGULAR JS中查找数组中的项索引

Javascript 如何在ANGULAR JS中查找数组中的项索引,javascript,angularjs,Javascript,Angularjs,例如,让我们以数组为例 $scope.users = ['John','Peter']; 如何获取John的索引 $scope.users.indexOf('John') 这不是特定角度的。这是一个JS数组方法。使用跟踪$index 例如, 然后你可以确定是不是约翰: <p ng-repeat = "user in $scope.users track by $index"> <span ng-if="$scope.users[$index] === 'John'"&g

例如,让我们以数组为例

$scope.users = ['John','Peter'];
如何获取John的索引

$scope.users.indexOf('John')

这不是特定角度的。这是一个JS数组方法。

使用
跟踪$index

例如,

然后你可以确定是不是约翰:

<p ng-repeat = "user in $scope.users track by $index">
  <span ng-if="$scope.users[$index] === 'John'">Here's John at {{$index}}</span>
</p>

这是约翰在{{$index}


在您的视图html
{{users.indexOf('John')}
或在您的控制器中使用$scope.users.indexOf('John')尝试此操作。

您身边的零代码?