[英]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.