Re: Elements array and query/queryAll methods
Dean Edwards <[email protected]>
| Newsgroups | gmane.comp.web.dom.general |
|---|---|
| Message-ID | <CAJMHKgwnKLHU_g_FLtuwqvuQ8x=vL3TgPbsTt2cD0voauC99KA@mail.gmail.com> |
On 8 April 2014 18:43, Domenic Denicola <[email protected]> wrote: > From: Dean Edwards <[email protected]> >> and I'm not convinced it works anyway, won't it potentially allow duplicates in the resulting Array? > > Why would that be a problem? JavaScript developers have duplicates in their arrays all the time. First of all it's counter-intuitive to how I'd expect it to work - the idea stemmed from jQuery's find() method which does not return duplicates. The main problem is that if I loop over the result and perform some operation on the elements in the array (e.g. adding a child element) then I'm potentially doing the same thing multiple times to the same element. To stop myself from doing this I'd have to keep track of which elements I'd already manipulated. This is slow and cumbersome and contrary to the behaviour I'd expect.