How to remove last few characters of String using JavaScript Slice ?

Every time trim the last 6 characters from the phone number.

For example, +919895590123 and make it +919895. Now you can use slice straight away if you know where to end.

'+919895590754'.slice(0,7)
// ## `+919895`

But it doesn’t work is it’s different length phone number like +1219895590345.

So the solution would be to use negative index for end parameter.

'+1219895590345'.slice(0,-6)
// ## '+1219895'