Uncaught TypeError: Cannot read property 'toUpperCase' of undefined
<p>I am trying to convert two strings to same format like toUpperCase/toLowerCase to compare two strings regardless of case sensitive in javaScript. Below is my function.</p>

<pre><code>    function submitForm() {

    var usernames=['one','two','Test'];
    var cpusername = "test";
            var flag = 0;

   if (cpusername !== "")
                {
    for (var k = 0; k &lt; usernames.length; k++)
                {
        var upperCasecpusername=cpusername.toUpperCase();
        var getusername= usernames[k];
        var upperCaseusername=getusername.toUpperCase();

                    if (upperCasecpusername === upperCaseusername)
                    {
                        flag=1;
     console.log(flag);
            //document.getElementById('cpusername').value = '';
                $.messager.alert("Message", "Someone already has username"+cpusername+". Try another!!", '');                    


                    }
                }
                }
</code></pre>

<p>am getting this error Uncaught TypeError: Cannot read property 'toUpperCase' of undefined .I have also tried to convert toString() first and then to toLowercase() .It was also erred (toString() undefined). Also suggest me if any other ways to compare two string regardless of case sensitive. Thanks!</p>