8
crisz
6y

It's 2019. Why do people keep using $.each?

Comments
  • 6
    No idea what that does. So I guess I'm not one of them 😂
  • 5
    @olback it iterates on an array. In an ugly way:

    $.each(array, function (el) {
    // do things
    });

    in place of:

    array.forEach(function (el) {
    // do things
    });
  • 3
    @crisz That's pointless 🤦‍♂️
  • 6
    Old IE compatibility ;)

    For IE versions not even Microsoft supports.
  • 4
    why people still use jquery?
  • 3
    Because Jquery.
    Plus isn't array.foreach() still a prototype?

    Why don't people just write a for() loop instead 🤷‍♂️
  • 2
    @lknk true, but this is JS, so it shouldn't be looping through thousands of indexes in the first place where the performance of a second temporary variable would have any actual impact.
  • 3
    forEach is an array method, $.each can be used on any type of collection.

    They are very differently behaving methods.
  • 3
    What about Array.from(array).forEach()?

    Well, it's longer to type, but you avoid importing a heavy library.

    The alternative is knowing the fucking variable you are operating on and using the fucking appropriate method
  • 1
    As someone who's «forced» to use it, I use it simply because I have so much work and so little time that i can't focus on performance, I need to get things done ASAP.
  • 3
    @lknk If you're like me and shit at designing you're gonna implement bootstrap which comes with jQuery and if you already have it, why not use it?
  • 3
    @lknk yeah beause reading and writing 2 variables is quicker than a function call. Of course for() is faster than foreach. Always. By fucken definition.
  • 0
    @Voxera
    >not using Babel to convert your JavaScript scripts to backwards compatible code
  • 1
    @EdoPhoenix well yeah than i would use it too, but if it‘s not a dependency anywhere i would not add it.
  • 0
    @C0D4 @lknk u guys know that for is superior in speed to forEach. For is faster and hard to beat for forEach.
Add Comment