如何比较集合中的多个值?
How can I do a comparison of more than one value in a collection?
我做的对比如下:
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);
你没有在第二次比较中使用箭头函数(=>
)。您还错误地使用赋值运算符 (=
) 而不是同情运算 (==
或 ===
):
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);
我做的对比如下:
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);
你没有在第二次比较中使用箭头函数(=>
)。您还错误地使用赋值运算符 (=
) 而不是同情运算 (==
或 ===
):
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);