[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

lastIndexOf does not work in Internet Explorer

I have the following code:
var currentServerlist = [];
    var newServerIp = document.getElementById('add_server').value; 
    if( CurrentServerIP != newServerIp )
    {
        $('#failoverServers td.row_selector').each(function() {
        var row = $(this).closest('tr');
        var serverIp = row.find('td[rel=ip]').text();
        currentServerlist.push(serverIp);	
        });

        if(currentServerlist.lastIndexOf(newServerIp) != -1)
        {
            return true;
        }
        return false;

Open in new window


But I find that the lastIndexOf does not work in InternetExplorer (It does in Chrome).

How can I fix this?
0
Wanting2LearnMan
Asked:
Wanting2LearnMan
  • 2
3 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
add it to your javascript file:

if (!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf= function(obj, start) {
var index=-1;
     for (var i = (start || 0), j = this.length; i < j; i++) {
         if (this[i] === obj) { index = i; }
     }
     return index;
}
}

Open in new window

0
 
RashadhourieCommented:
The lastIndexOf() method is not supported in Internet Explorer 8 and earlier, you'll need  sedgwick's solution
0
 
Meir RivkinFull stack Software EngineerCommented:
both indexOf and lastIndexOf are not supported.
btw, i based my solution on this:

how-to-fix-array-indexof-in-javascript-for-ie-browsers
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now