var str = 'fred red bed said', searchTerm = 'bed',
arr = str.split(' ');
function removeSubstr(str, substr){
tmp = " " + str + " ";
substr = " " + substr + " ";
if (tmp.indexOf(substr) !== -1 ) {
tmp = tmp.replace(substr, "").trim();
return tmp
}
return str;
}
function removeSubstr2(str, substr){
var len = str.length, tmp = (" " + str + " ").replace(" " + substr + " ", "").trim();
if ( str.length < len ) return tmp;
return str;
}
function removeSubstr3(str, substr){
var strSpl = str.split(' '), idx = strSpl.indexOf(substr);
if ( idx > -1) {
return strSpl.splice(idx, 1).join(' ');
}
return str;
}
function removeElem(arr, substr){
var idx = arr.indexOf(substr);
if ( idx > -1) {
return arr.splice(idx, 1);
}
return arr;
}