如何比较集合中多个值?

时间:2019-10-02 05:34:57

标签: javascript comparison-operators

我做了如下比较:

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);

1 个答案:

答案 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);