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:

Functions in javascript

25-05-2018 functions javascript es5 es6 arrow functions named functions Closures Nested Functions Callbacks Arrow functions.

How to search text in string using php ?

29-10-2017 php search string search

How To Get Your Blogs Posts Using Blogger API

30-07-2017 blogger api json php

How to insert bulk information into database in single query execution

18-03-2017 insert sql bulk database

Convert Time 24 hrs to 12 hrs format In javascript

12-03-2017 date javascript 12hrs convert