You have a typo in your question, you've meant:
I want return always 0 for booth Google, google, GOOGLE, gooGle
^
The jQuery function $.inArray
executes case-sensitive comparison, so, G !== g
What you can do, is convert to either upper or lower case both Google
string and values within Arrays
. Further, your array arrays
will contain the original values after the conversion.
With function map
you can accomplish that very smoothly.
var arrays = ['Google', 'Yahoo', 'Bing'];
console.log($.inArray('Google'.toUpperCase(), arrays.map((e) => e.toUpperCase())));
console.log($.inArray('google'.toUpperCase(), arrays.map((e) => e.toUpperCase())));
console.log(arrays);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
See? was printed
0
for both executions and your array
arrays
contains the same values.
Resources