Home » JavaScript Tutorial

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"





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.