The difference is in the second argument. The second argument to substring is the index to stop at (but not include), but the second argument to substr is the maximum length to return.
Substring is a string operation that extracts characters from a string between two specified indices. const sentence = "Jithu Thomas"; console.log(sentence); const substring = sentence.substring(6,12); console.log(substring); JavaScript Copy Output Substr() Substr is a string operation that ext...
substr()接受一个负起始位置作为从字符串末尾的偏移量。 substring()没有。 来自MDN: 如果start 为负数,则 substr()将其用作字符串末尾的字符索引。 所以总结一下功能差异: substring(begin-offset, end-offset-exclusive)其中begin-offset 为0或更大 substr(begin-offset, length)其中begin-offset 也可以是...
In the world of JavaScript, there are lots of ways to manipulate strings as JS provides many methods to do so. Two of those methods are substr() and substring(). At first glance, they might seem identical - both are used to extract parts of a string. However, they have subtle differe...