-1

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?

GigiProve
  • 337
  • 1
  • 5
  • 15

1 Answers1

3

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)
Code Maniac
  • 37,143
  • 5
  • 39
  • 60