Lodash check value in a array case insensitive

后端 未结 2 1170
萌比男神i
萌比男神i 2020-12-20 13:05

I am checking for a value in a array using lodash _.some function. but its case sensitive. Is there any function for case insensitive search in

相关标签:
2条回答
  • You can pass a function to _.some where you compare the name in case insensitive way, for example:

    _.some(divisionList, function(division) {
      return division.Name.toLowerCase() === divisionName;
    })
    
    0 讨论(0)
  • 2020-12-20 13:38

    The "native" javascript (ES6) solution using Array.some() function (as an alternative):

    var divisionName = "division 2",  // for example
        hasDivision = divisionList.some((obj) => obj["Name"].toLowerCase() === divisionName);
    
    console.log(hasDivision);  // true
    
    0 讨论(0)
提交回复
热议问题