theJava
theJava

Reputation: 15044

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.

Upvotes: 0

Views: 1079

Answers (2)

Christo
Christo

Reputation: 9085

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

Upvotes: 1

jon_darkstar
jon_darkstar

Reputation: 16778

You can use toUpperCase on both of the strings

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

Upvotes: 2

Related Questions