(function() {
function takeRecordingAway() {
try {
let $title = document.querySelector('.progTitle');
let splitInfo = $title.textContent.split(' ');
let lastInd = splitInfo.lastIndexOf('Recording');
let filterResult = splitInfo.slice(lastInd, splitInfo.length).join('');
let finalResult = splitInfo.join('').replace(filterResult, '');
$title.textContent = finalResult;
} catch(e) {
console.log("Error", e);
}
}
function init() {
takeRecordingAway();
}
init();
})();
<div class="progTitle">Advisory Round: Key Steps for StartupsRecording is not available for this program</div>
I am trying to remove a phrase from a string. The phrase I want to remove is 'Recording is not available for this program' from this string:
'Advisory Round: Key Steps for StartupsRecording is not available for this program'
How would I be able to find this phrase and remove it?
Currently I am using this function that is not exactly working:
(function() {
function takeRecordingAway() {
try {
let $title = document.querySelector('.progTitle'); //div containing the phrase
let splitInfo = $title.textContent.split(' ');
let lastInd = splitInfo.lastIndexOf('Recording');
let filterResult = splitInfo.slice(lastInd, splitInfo.length).join('');
let finalResult = splitInfo.join('').replace(filterResult, '');
$title.textContent = finalResult;
} catch(e) {
console.log("Error", e);
}
}
function init() {
takeRecordingAway();
}
init();
})();