btw ,there's a interesting topic ,too. if you are doing array concat job, you could take a look for this. http://jsfiddle.net/We9p9/1/
The keypoint is , even when you are using array.push , *ary.push(1,2,3,4,5);* is still faster then *ary.push(1); ary.push(2); ary.push(3); ary.push(4); ary.push(5); * 2011/3/16 Diego Perini <[email protected]>: > On Wed, Mar 16, 2011 at 12:14 PM, Rob Griffiths <[email protected]> wrote: >> >>> Length should return the value of the last index + 1, so in that case >>> length will return 8 >> >> I knew I should have checked before stating that. >> >> -- >> Rob Griffiths >> http://bytespider.eu >> @bytespider >> https://github.com/bytespider >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/[email protected]/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/[email protected]/ >> >> To unsubscribe from this group, send email to >> [email protected] >> > > I use the following to convert/concat NodeList to Array: > > // concat elements to data array > concatList = > function(data, elements) { > var i = -1, element; > if (data.length === 0 && Array.slice) > return Array.slice(elements); > while ((element = elements[++i])) > data[data.length] = element; > return data; > }, > > On older browsers this was the fastest "loop" among many browsers at > the time I tested it and on newer browsers this is not used/necessary. > > I am not sure using Firefox "Array.slice" shortcut when "data" array > is empty is worth it (nowadays) so the bare bone JS should be this: > > // concat elements to data array > concatList = > function(data, elements) { > var i = -1, element; > while ((element = elements[++i])) > data[data.length] = element; > return data; > }, > > At that time another interesting thing I observed was that Webkit > based browser were also faster to access DOM element in the ancient > way using the "nodelist.item(n)" notation (really much faster). > > The point is performances are improving at a fast pace in every > browser engine so small speed improvements like these are becoming > less and less relevant, it is still a funny exercise though :) > > -- > Diego > > -- > To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
