indexOf implementation for WScript and CScript

One of the problems with WScript is that it implements not the normal JavaScript we all use in web but rather JScript, which is actually JavaScript 1.5. One of the function which do not exist in version 1.5 is Array.indexOf

Here is a patch that allows using it:

if ( typeof(Array.prototype.indexOf) === 'undefined' ) {
    Array.prototype.indexOf = function(item, start) {        
        var length = this.length
        start = typeof(start) !== 'undefined' ? start : 0
        for (var i = start; i < length; i++) {
            if (this[i] === item) return i
        return -1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.