I want to get a substring that is before the nth point. For example I have:
let str = "my.string.is.like.that"
Now suppose I want substr= "my.string.is.like"
that is all before the 4th point. How can I do that?
I want to get a substring that is before the nth point. For example I have:
let str = "my.string.is.like.that"
Now suppose I want substr= "my.string.is.like"
that is all before the 4th point. How can I do that?
You can use split
and join
,
Second parameter in split is used to limit the number of element to be included in final output
let str = "my.string.is.like.that"
let limited = str.split('.',4).join('.')
console.log(limited)