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:
Example for Conditional Operator in php16-04-2017 php Conditional Operator example |
How to convert html to pdf in Node js12-03-2017 pdf convert html node js |
Remove last two characters from given string06-03-2017 substring javascript remove |
Filter for replace text in Angular Js05-03-2017 filter replace angular js |
Call a function every second or 5 seconds in javascript22-02-2017 setinterval function calling |