+ 1

What is the difference between substring(), substr() and slice() in Javascript?

Can anyone explain this with an example or preferably a code?

28th Oct 2018, 9:30 AM
Avi Takiyar
Avi Takiyar - avatar
1 Answer
+ 2
substring take start index and end index substr take start index and length slice same as substring with abit different behavior ex let x="Hello" x.substring(1,3) //el x.substr(1,3) //ell //slice can take negative value as end index x.slice(1,-3) //e
28th Oct 2018, 11:17 AM
Taste
Taste - avatar