Search array inArray but ignore case

旧时模样 提交于 2019-12-06 14:09:57

Since it looks like you have control of the values (and are making them lowercase), you can do a pretty simple change from:

if (($.inArray((this.value), option) > 0)

to

if (($.inArray((this.value.toLowerCase()), option) > 0)

Demo at http://jsfiddle.net/dRpmq/3/

From Case insensitive search in array JavaScript provide a Method indexOf() which is used to search object from array but this is case sensitive.

Jquery provide a method jQuery.inArray() To search object in array but this is case sensitive also i.e “a” is not equal to “A”. So we have to make our own function, Following is small javascript function which return index of object if found in array otherwise return -1 and this is case insensitive method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!