1

I have a case like,

var givenTerms = [Tree, Plant, River, Ocean, Place, Sky];
var check = 'SKY';
if ($.inArray(check, givenTerms()) !== -1) {
    // say it is present in givenTerms
}

This case fails as it is case sensitive. I could not use givenTerms.toLowercase() as it is an array and not a single term. Is there any other possibility to make this if case true.

Any suggestion could be helpful.

Santiago Varela
  • 2,199
  • 16
  • 22
Jeya Suriya Muthumari
  • 1,947
  • 3
  • 25
  • 47
  • You can use regex. `new RegExp("SKY", "i")` – Rajesh Mar 30 '17 at 10:01
  • Always have constant array in lower case and compare it with the same case... – Rayon Mar 30 '17 at 10:01
  • 2
    Possible duplicate of [Any way to make jQuery.inArray() case insensitive?](http://stackoverflow.com/questions/3390930/any-way-to-make-jquery-inarray-case-insensitive) – Shogunivar Mar 30 '17 at 10:02

1 Answers1

0

First you need to update/Create a new array for matching string. Here I update the original collection that match search term. Check the result here

var givenTerms = [Tree, Plant, River, Ocean, Place, Sky];
var check = 'SKY';  
givenTerms = ((givenTerms.toString()).toUpperCase()).split(",");
if (givenTerms.indexOf(check) >= 0) {
    alert(check +" found at "+ givenTerms.indexOf(check));
}
Ananth Cool
  • 125
  • 8