Is the Javascript String length constant time? -
i'm new js, , realize length considered property. received comment not use str.length in loop:
for (i=0; i<str.length; i++){...}
vs
var len = str.length; (i=0; i<len; i++){...}
now, know str.length() constant time operation in java because length stored field in string class. again, strings immutable in java. not sure js strings though. str.length guaranteed constant time in js too? couldn't find discussed anywhere in web.
strings immutable in javascript. length
property not need computed each time accessed.
i created jsperf benchmark view here.
you'll notice speeds same.
Comments
Post a Comment