javascript substring vs substr

Solutions on MaxInterview for javascript substring vs substr by the best coders in the world

showing results for - "javascript substring vs substr"
Pia
19 Feb 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"
Lisa
28 Jul 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
node js substr vs substringsubstring and substr in javascriptsubstr jsstring substring javascriptjs substr vs substringsubstr vs substring vs slice javascriptsubstr vs substringjavascript difference between slice and substringjavascript difference between substr and substring examplesjs string substr vs substringsubstr vs substring jsnode substr vs substringsubstring or substrsubstr and substring in javascriptdifference between javascript substr 26 substringdifference between string and substring javascriptsubstring ke perameter ko javascript m kya bolte haisubstr vs substring function javascriptsubstr 28 29 vs substring 28 29 jssubstr vs stringjs substring vs substrsubstr vs substring in jsjavascript substr and substringwhat is the difference between substr and substring in javascriptsubstr vs substring javascriptsubtring jssubstring vs substrjasvascritp difference between substr and substringjavascript substr vs substringsubstring vs substr javascriptdifference between substring and substrjavascript difference between substr and substringsubstring vs skuce javascriptdifference between substr and substringnodejs substrnodejs substring vs substrsubstring jsjavascript diff between substr and substringjava substring vs substrstr vs substring javascriptjs string substr vs substring vs slicedifference between substring and substr in javascriptjavascript substri vs substring substring and substrsubstr in javascriptjavascript string substring vs substrwhich of the following function is used extract a sub string between the specified range 3ajavascript substring vs substr vs slicedifference between substr 26 sunstringsubstring vs substr jssubstring vs substr in javascriptsubstr vs substring in javascriptjavascript substring vs substrare substr and substring the same thing javascriptmethod extracts parts of a string 2c beginning at the character at the specified position 2c and returns the specified number of characters js subtring vs substrdifference between substr and substring in javascriptnode substring vs substrjavascript substring vs substr