Using slice remove last two characters from given string


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 




You might also like:

Use java script file client side and server side at a time in node js

30-07-2017 node js include call javascript

Detect AdBlock with JavaScript in my browser

30-07-2017 AdBlock javascript detect

Example for Conditional Operator in php

16-04-2017 php Conditional Operator example

How to get current date and time (yyyy-mm-dd H:i:s) using javascript

09-03-2017 javascript date time

How to change background color and color to the text using javascript

27-02-2017 css javascript colors