« Back to Index

Cheap ‘inArray’ trick by @ded

View original Gist on GitHub

Tags: #js

Quick ‘n’ Dirty Array.indexOf.js

/*
 * jsFiddle: http://jsfiddle.net/integralist/fL2Xv/
 * Original: http://twitter.com/#!/ded/status/90531502097575936
 */

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(item) {
        return ( Math.abs( ~this.indexOf(item) ) )-1;
    }
}