Solved

lastIndexOf does not work in Internet Explorer

Posted on 2013-02-07
3
580 Views
Last Modified: 2013-02-24
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
Comment
Question by:Wanting2LearnMan
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 167 total points
ID: 38863161
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
 
LVL 1

Assisted Solution

by:Rashadhourie
Rashadhourie earned 83 total points
ID: 38863180
The lastIndexOf() method is not supported in Internet Explorer 8 and earlier, you'll need  sedgwick's solution
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 167 total points
ID: 38863183
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now