Arbejdsglæde
Arbejdsglæde

Reputation: 14088

JavaScript variable not is undefined in IE9

Hello I have next JS code (this code not my own)

 function somename(f) 
    var procName = "";
    var procParams = new Array();
    var parseEl = "";
    var parseEls = new Array();
    var parseInd = 0;
    var procParamsInd = 0;
    var IsValRead = false;
    for (i = 0; i < f.length; i++) {
        if (f[i] == "(")
            break;
        else
            procName = procName + f[i];
    }

}

I will redo it to much better way to find data before "(", but i wounder why procName variable is always undefined in IE9 in all browsers all working well.

Upvotes: 0

Views: 394

Answers (2)

HBP
HBP

Reputation: 16033

I have a vague recollection that at least some versions of IE do not support indexing to access string characters. Try using charAt instead; or a better algorithm. It is almost certainly the f[x] which is causing your undefined's.

Upvotes: 1

Joseph
Joseph

Reputation: 119847

A better way to get the substring before ( is this:

var f = "name(2,4,5)",
    procName = f.slice(0, f.indexOf('(')); //slice from start until before "("

console.log(procName)​; //name

Upvotes: 1

Related Questions