String slice() Method with Example in JavaScript

JavaScript String slice() Method: Here, we are going to learn about the slice() method of the string in JavaScript with Example.
Submitted by Shivang Yadav, on February 16, 2020

JavaScript | String slice() Method

The String.slice() method in JavaScript is used to return a part of the string. The starting and ending index of the part to be sliced is provided as the parameter of the string.

Syntax:

    String.slice(startIndex, endIndex);

Parameter(s):

The method accepts two parameters, they are the starting and ending index of the sliced string which is extracted.

Return value:

The return type of this method is string which is the sliced output of the given string.

Browser support: Chrome, Internet explorer, Mozilla, Safari, Opera mini.

Example:

str = "includehelp"
//"includehelp"
str.slice(6)
//"ehelp"
str.slice(0,7)
//"include"
str.slice(6,-1)
//"ehel"

JavaScript String Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.