Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  53] [ 1]  / answers: 1 / hits: 15295  / 11 Years ago, thu, january 30, 2014, 12:00:00

I found this snippet, but I am not sure if it should have -5 or -6, because I do not what exactly substr(negative) does.



('00000'+(15).toString(16)).substr(-5)

More From » substring

 Answers
101

substr() returns the a string made up of the last N characters, when -N is passed to it.


"Hello".substr(-2) => "lo"


From the docs:



If start is negative, substr uses it as a character index from the end
of the string. If start is negative and abs(start) is larger than the
length of the string, substr uses 0 as the start index.



[#72848] Wednesday, January 29, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;