Search code examples
javascriptcase-insensitive

javascript: ignoring case sensitivity of strings


In JavaScript, I'm trying using the user's input to search my database. For example, user input is "monster", and my database's data is "Monster". How can I have it match regardless of it's casing?


Solution

  • Javascript string case-insensitive comparisons can be performed with string.toUpperCase.

    if (input.toUpperCase() === "OTHER STRING")
        ....
    

    (I'm assuming your database example is just an example as databases usually ignore the case of strings :)