javascript - Ignore case-sensitive input in an array? -


i want search value in array, search should ignore lower/upper-case letters. how can accomplish this?

this code:

$.ajax({ type: "get", url: "ajax.php", datatype: "json", data: { pagetype: pagetype, input: request.term, datastring: 'getpageinfo' }, success: function(data)  {                                                var values = $.map(data, function(item) { return {id: item.id, label: item.label, value: item.value}; });    (var = 0; < values.length; i++) {     if (values[i].label.split(',').indexof(request.term) >= 0) {        var found = values[i];     } }        if (!found) values.push({id: 0, label: request.term + ' hinzufügen', value: request.term}); response(values);        

it's giving option create new entry, if input matches entry prevent creating duplicate entries user can see in last line. request.term value entered user , values array.

so example, if i'm searching "berlin" or "berlin" or "berlin" , entry in database "berlin", should still mark item found in array.

one option force things upper- or lower-case beforehand:

var iterm = request.term.tolowercase(); // ... if (values[i].label.tolowercase().split(',').indexof(iterm) >= 0) { 

alternately turn request.term case-insensitive regular expression, doing involves escaping of characters in might special in regular expressions, pain. you'd have looking through lot of values tolowercase overhead make me want @ complexity.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -