Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 搜索大小写字符_Javascript_Json - Fatal编程技术网

Javascript 搜索大小写字符

Javascript 搜索大小写字符,javascript,json,Javascript,Json,我的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 = []; /

我的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());
[
{“姓”:“诺伊斯”,“性别”:“男”,“病人”:19389,“名”:“斯科特”,“年龄”:“53岁”},
{“姓氏”:“noyce724”,“性别”:“男性”,“patientID”:24607,“名”:“丽塔”,“年龄”:“0Y”}
]
var searchBarInput=TextInput.value;
变量结果=[];//初始化结果数组
对于(变量i=0;i

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

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

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

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

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

aaaah
toUpperCase
=paaah
toUpperCase
=P的替代方案