![]() inde圎nd represents a character that's before indexStart), then an empty string is returned. However, if inde圎nd <= indexStart after normalizing negative values (i.e. You can, of course, have instances where both values are negative, for example: the substring ends at max(inde圎nd + str.length, 0)). Similarly, if inde圎nd < 0, then the index is counted from the end of the string (i.e. is equivalent to `max(-4 + str.length, 0) = 6`: the substring starts at max(indexStart + str.length, 0)). If indexStart < 0, then the index is counted from the end of the string (i.e. When either, or both, arguments are negative, then it counts backwards from the end of the string to find the indexes. In case of substring(), if either, or both, arguments are negative or NaN, then it's treated as 0. substring() will swap the two arguments Ĭonsole.log(str.substring(6, 2)) // 'sign'Ĭonsole.log(str.substring(2, 6)) // 'sign'ĭifferences When indexStart or inde圎nd Is Negative or NaN ():.However, they have some minor differences in terms of when:ĭifferences When indexStart Is Greater Than inde圎nd Either argument is greater than the string's length - the string's length will be used in both cases.inde圎nd is omitted - they both extract characters to the end of the string.indexStart equals inde圎nd - they both return an empty string.Syntactically, both () and () are similar:Īnd, they both behave in the same way when:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |