let str4 = 'a_baba_galamaga_tvoe_korito_est_nesti';
let a4_from = 'k';
let a4_to = 't';
const f4 = (str, a, b) => {
let strNew = str4.split('_');
let res = strNew.find((word,index,arr) => {
if (
word.indexOf(a) !== -1 &&
word.indexOf(b) !== -1 &&
word.indexOf(b) - word.indexOf(a) > 0
){
return true;
}
});
document.querySelector('.out-4').innerHTML = (res !== undefined)
? res.slice(res.indexOf(a) + 1, res.indexOf(b))
: `undefined`;
}
f4(str4, a4_from, a4_to);