Using slice remove last two characters from given string

slice
remove

The basic syntax for the slice is 

array.slice(start, end)

The sample string is 

var text = "welcome!";

Now, i am trying to remove last character from the above string using slice.

text = text.slice(',',-1);

Now the result is : welcome

Slice is also used for remove values from array, here is the example.

var fruits = ["Orange", "Strawberry", "Banana", "Orange", "Mango"];
var myBest = fruits.slice(-3, -1);

the result is 

Orange,Lemon

 

 

You might also like:

Check null values in JavaScript?

04-02-2019 JavaScript null check null value

Detect AdBlock with JavaScript in my browser

30-07-2017 AdBlock javascript detect

Filter for change Date Time format (MM-dd-yyyy HH:mm) in Angular Js

05-03-2017 mm-dd-yyyy HH:MM date formats angular js

Sample Validations in javascript

22-02-2017 validations javascript

Send Mail in Node Js

21-02-2017 node js mail npm module