Javascript String trimx()

Description

Javascript String trimx()


String.prototype.trimx = function() {
    return /(\S.+\S)/.exec(this)[0]
}

String.prototype.searchx = function(str) {
    return this.match(str).index
}



console.log('  Hi World       '.trimx());
console.log('  Hi World       '.searchx('World'));



PreviousNext

Related