William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

JavaScript: search in Array

JavaScript: search in Array

The following are the version of ‘search in Array’ from select2 js:

    if (typeof indexOf !== 'function') { //default: "undefined"
        function indexOf(value, array) {
            var i = 0, l = array.length;
            for (; i < l; i = i + 1) {
                if (equal(value, array[i]))
                    return i;
            }
            return -1;
        }
    }
    if (typeof equal !== 'function') {
        function equal(a, b) {
            if (a === b)
                return true;
            if (a === undefined || b === undefined)
                return false;
            if (a === null || b === null)
                return false;
            if (a.constructor === String)
                return a + '' === b + '';
            if (b.constructor === String)
                return b + '' === a + '';
            return false;
        }
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: