Difference between the substr() and substring() in JavaScript? | substring substr javascript
TheJavaScriptstringisanobjectthatrepresentsasequenceofcharacters.Thesubstr()methodextractspartsofastring,beginningatthecharacteratthespecifiedposition,andreturnsthespecifiednumberofcharacters.Thesubstring()methodreturnsthepartofthestringbetweenthestartandendindexes,ortotheendofthestring.Syntax string.substr(start,length) start:Thepositionwheretostarttheextraction,indexstartingfrom0.length:Thenumberofcharacterstoextract(optional).example vars="JavaScript"; varst=s.substr(4,6);...
The JavaScript string is an object that represents a sequence of characters. The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters. The substring() method returns the part of the string between the start and end indexes, or to the end of the string.
Syntax string.substr(start, length) start: The position where to start the extraction, index starting from 0. length: The number of characters to extract (optional). example var s = "JavaScript"; var st = s.substr(4, 6); alert(st);The above code would return "Script".
Syntax string.substring(start, end) start: The position where to start the extraction, index starting from 0. end: The position (up to, but not including) where to end the extraction (optional). example var s = "JavaScript"; var st = s.substr(...