wahsaga: Array.indexOf("String") läuft in FF, nicht aber in MSIE

Beitrag lesen

hi,

Exakt.

Und da dort noch ein optionaler fromIndex erwähnt wird, könnte man die Methode auch noch dazu kompatibel erweitern:

if(!Array.indexOf)  
{  
  Array.prototype.indexOf = function(el, fromIndex)  
  {  
    // fromIndex  
    // The index at which to begin the search. Defaults to 0, i.e. the whole array will be searched.  
    if(!fromIndex) { var fromIndex = 0; }  
  
    // If negative, it is taken as the offset from the end of the array.  
    // Note that even when the index is negative, the array is still searched from front to back.  
    // If the calculated index is less than 0, the whole array will be searched.  
    else if(fromIndex < 0) {  
      fromIndex += this.length;  
      if(fromIndex < 0) { fromIndex = 0; }  
    }  
  
    // If the index is greater than or equal to the length of the array, -1 is returned, i.e. the array will not be searched.  
    else if(fromIndex >= this.length) { return -1; }  
  
    for(var i = fromIndex; i < this.length; i++) { if(el == this[i]) { return i; } }  
    return -1;  
  }  
}

gruß,
wahsaga

--
/voodoo.css:
#GeorgeWBush { position:absolute; bottom:-6ft; }