GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — Difference between substr() and substring() in JavaScript - GeeksforGeeks Difference between substr() and substring() in JavaScriptLast Updated : 11 Jul, 2025 In JavaScript Both of the functions are used to get the specified part of the string, But there is a slight difference between them. substr() and substring() are string methods used to extract parts of a string. The main difference is that substr() accepts a length parameter, while substring() accepts start and end indices. JavaScript str.substr() FunctionThe str.substr() function returns the specified number of characters from the specified index from the given string. Syntax:str.substr(start, len);Example: This example uses only one parameter for both functions and produces the same output.
Output Str.substr(7) = rGeeks Str.substring(7) = rGeeks JavaScript str.substring() FunctionThis function gets the characters from a string, between two specified indices, and returns the new string. Syntax:str.substring(start, end);Example: This example uses the parameter (3, 7) for both functions and returns the output.
Output Str.substr(3, 7) = ksForGe Str.substring(3, 7) = ksFo Difference between substr() and substring()
Comment Explore | |||||||||||||||||||||
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |