我做了如下比较:
var searchValue = 'Apple'
var searchValue2 = 'Orange'
var index = $scope.sEntitiesListTest.findIndex(x => x.ItemText === searchValue);
我可以比较多个值,例如
var index = $scope.sEntitiesListTest.findIndex(x => x.ItemText === searchValue && x => x.ItemValue = searchValue2);
答案 0 :(得分:4)
在第二个比较中,您没有箭头功能(=>
)。另外,您错误地使用赋值运算符(=
)而不是同情运算(==
或===
):
var EntitiesListTest = [{ItemText: "Test Text", ItemValue: "Test Value"},{ItemText: "Apple", ItemValue: "Orange"}]
var searchValue = 'Apple';
var searchValue2 = 'Orange';
var index = EntitiesListTest.findIndex(x => x.ItemText === searchValue && x.ItemValue == searchValue2);
console.log(index);