You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9 lines
335 B
JavaScript
9 lines
335 B
JavaScript
function remove_first_occurrence(str, searchstr) {
|
|
var index = str.indexOf(searchstr);
|
|
if (index === -1) {
|
|
return str;
|
|
}
|
|
return str.slice(0, index) + str.slice(index + searchstr.length);
|
|
}
|
|
|
|
console.log(remove_first_occurrence("The quick brown fox jumps over the lazy dog", 'the')); |