How do I truncate a string after or before a pattern?
Say if I have a string "abcdef"
I need to truncate everything after "abc"
so the output will be:
def
and if i say truncate before "def"
the output should be:
abc
Below is the code that I tried
var str1 = "abcdefgh";
var str2 = str1.substr(str1.indexOf("abc"), str1.length);
console.log(str2);
I didn't get the output.
I'm stuck here any help will be much appreciated.