简体   繁体   中英

searching for character with lowercase and uppercase

My JSON data

[
{"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());

I get the result, but i want it for both matching uppercase and lowercase when i search for a character which starts in the word.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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