使用indexOf并返回布尔值?

问题描述 投票:0回答:1

您好,我想用indexOf()创建一个条件,如果存储在dataservice.dic.neu.rechtsformkanzlei中的输入在数组中具有索引,则该条件将在数组中查找,然后返回布尔值。但是我不知道有人可以帮助我吗?我当前的代码不起作用,它只给我-1。希望有人有一个主意。 :)

当前我的代码如下:

数组= [值1,值2,值3,值4]

$scope.vergleich = function() { return 
  $scope.array.indexOf(dataservice.dic.alt.rechtsformkanzlei)|| 
$scope.array.indexOf(dataService.dic.neu.rechtsformKanlei) !== -1)
javascript angularjs indexof
1个回答
0
投票

您可以使用includes()

$scope.vergleich = function() { return 
 ($scope.array.includes(dataservice.dic.alt.rechtsformkanzlei)|| 
$scope.array.includes(dataService.dic.neu.rechtsformKanlei)
© www.soinside.com 2019 - 2024. All rights reserved.