showing results for - "javascript substr vs substring"
Finn
22 Nov 2020
1var string = "This is a string";
2var a = string.substring(2, 5); //Start at index 2 and end at index 5
3console.log(a); //output "is "
4var b = string.substr(2, 5); //Start at index 2 and stop after 5 characters
5console.log(b); //output "is is"
Catalina
11 Sep 2020
1let demo = 'This is a normal sentence';
2
3// substr 
4// The substr method takes two parameters
5// param 1 - the starting index to copy from a string
6// param 2 - the number of characters that must be copied from the starting index
7
8let newDemo = demo.substr(3, 5);
9// newDemo would be 's is ' 
10
11// substring
12// The substring method takes 1 mandatory and 1 optional parameter
13// param 1 - the starting index to copy from a string
14// param 2 - (optional) the ending index that will be copied until from the starting index. 
15		// - it will not include the ending index position
16		// - if this param is left blank. it defualts to the rest of the string
17
18let newDemo = demo.substring(0, 3);
19// newDemo would be 'Thi'
20
21let newDemo = demo.substring(3);
22// newDemo would be 's is a normal sentence' 
23
24
queries leading to this page
javascript diff between substr and substringjavascript substr vs substringjavascript substri vs substringdifference between javascript substr 26 substringsubstring vs substr in javascriptstr vs substring javascriptsubstring vs substr jssubtring jssubstr vs substring in javascriptsubstring ke perameter ko javascript m kya bolte haijs string substring vs substrstring substring javascriptnode substring vs substrjavascript substring vs substr vs slicejavascript difference between substr and substring examplesjasvascritp difference between substr and substringsubstring jsjavascript difference between substr and substringjavascript substring vs substrsubstring vs substr javascriptnodejs substrwhich of the following function is used extract a sub string between the specified range 3ajavascript string substring vs substrsubstr vs substring in jsjs string substr vs substringjs substr vs substring vs slicesubstring or substrjava substring vs substr substring and substrsubstr in javascriptsubstr vs substringsubstring and substr in javascriptdifference between substr and substring in javascriptsubstring vs substrsubstr vs substring jsdifference between substring and substr in javascriptjs subtring vs substrjs string substr vs substring vs slicenodejs substring vs substrnode js substr vs substringjavascript substr and substringsubstr vs substring javascriptsubstr vs stringwhat is the differnece between substr and substring method in javascriptsubstr 28 29 vs substring 28 29 jsdifference between substr 28 29 and substring 28 29 in javascriptsubstr vs substring vs slice javascriptjs substr vs substringsubstr vs substring function javascriptdifference between substr 26 sunstringsubstring vs skuce javascriptsubstr jsare substr and substring the same thing javascriptsubstr and substring in javascriptdifference between string and substring javascriptwhat is the difference between substr and substring in javascriptsubstr vs strstr javascriptdifference between substr and substringdifference between substring and substrnode substr vs substringjavascript difference between slice and substringjs substring vs substrmethod extracts parts of a string 2c beginning at the character at the specified position 2c and returns the specified number of characters javascript substr vs substring