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:
A Very Big Sum | Javascript | hackerrank07-05-2020 A Very Big Sum Javascript hackerrank |
Navigate to another page using java script06-03-2017 javascript redirection navigation |
How to set or update or push the values into Object in javacript27-02-2017 javascript set update push object |
Email validation regular expression in javascript22-02-2017 email validation regex |
Get Unique values from array/object in javascript19-02-2017 javascript unique remove repeated values from array |