pbojinov
2/14/2013 - 8:18 PM

String.prototype.contains

String.prototype.contains

/**
 * Wrapper for indexOf() to return true || false if string is contained within another string
 * Will not not extend String if 'contains' already exists
 * 
 * @param {String} 
 * @return {Boolean}
 */
if (typeof String.prototype.contains === 'undefined') { 
    String.prototype.contains = function(it) { 
        return this.indexOf(it) !== -1; 
    }; 
}

'pbojinov'.contains('p') === true;