Javascript 搜索大小写字符
我的JSON数据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 = []; /
[
{"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
=paaahtoUpperCase
=P的替代方案