繁体   English   中英

搜索大写和小写字符

[英]searching for character with lowercase and uppercase

我的JSON数据

[
{"lastName":"Noyce","gender":"Male","patientID":19389,"firstName":"Scott","age":"53Y,"}, 
{"lastName":"noyce724","gender":"Male","patientID":24607,"firstName":"rita","age":"0Y,"}
]

var searchBarInput = TextInput.value;
var results = []; // initialize array of results
for (var i = 0; i < recentPatientsList.length; ++i) {
  if (recentPatientsList[i].lastName.indexOf(searchBarInput) == 0) {
    results.push(recentPatientsList[i].lastName);
  }
}
alert('Results: ' + results.toString());

我得到了结果,但是当我搜索以单词开头的字符时,我希望它同时匹配大写和小写字母。

您可以在两个字符串上使用toUpperCase

if (recentPatientsList[i].lastName.toUpperCase().indexOf(searchBarInput.toUpperCase()) == 0) {
if(recentPatientsList[i].lastName.toLowerCase().indexOf(searchBarInput.toLowerCase()) == 0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM