Solved

lastIndexOf does not work in Internet Explorer

Posted on 2013-02-07
3
587 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now