我如何比较一个集合中的多个值?

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

我进行如下比较:

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

javascript comparison-operators
1个回答
1
投票

您在第二个比较中没有箭头功能(=>)。另外,您错误地使用赋值运算符(=)而不是同情操作(=====):

var EntitiesListTest = [{ItemText: "Test Text", ItemValue: "Test Value"},{ItemText: "Test Text2", ItemValue: "Test Value2"}]
var searchValue = 'Test Text2';
var searchValue2 = 'Test Value2'
var index = EntitiesListTest.findIndex(x => x.ItemText === searchValue && x.ItemValue == searchValue2); 
console.log(index);
© www.soinside.com 2019 - 2024. All rights reserved.