Join the DZone community and get the full member experience.Join For Free
(ecmascript 5.1 specification
) is the first logical choice to retrieve a part of the string. this
function can accept two numbers, the
(exclusive) character position, respectively. in case the end value is smaller than the start, substring is smart enough to
the values before doing the string extraction. an example of substring is illustrated in this code snippet:
var a = 'the three musketeers'; a.substring(4, 9); 'three' a.substring(9, 4); 'three'
). however, the parameters for
character position and the
of characters to be extracted, respectively. this is shown in the following fragment:
var b = 'the three musketeers'; b.substr(4, 9); 'three mus' b.substr(9, 4); ' mus'
prevention is the best cure. be advised of your function name!
Published at DZone with permission of Ariya Hidayat, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.