jQuery $.each vs. JavaScript .forEach

Performance wise they both are similar Perf test

forEach is implemented native in the Browser which makes it easier to maintain for non-jquery developers while on the other hand each offers better readability.


Operationally is a bit vague but here is how $.each is implemented.

each implementation

[].forEach() would most likely be implemented in native code for each browser.

Without doing performance testing, they are pretty similar. Although if you can remove jQuery altogether that is at least a few kb the browser does not need to load.


The comments on the original question are good for your specific scenario of wanting to remove individual items.

On a more general note, some other differences:

1) Array.forEach() obviously requires that you're iterating across an array. The jQuery approach will let you iterate across the properties of an object.

2) jQuery.each() allows short-circuiting. Check out this post that mentions use of "some()" and "every()" for doing similar things with pure js:

How to short circuit Array.forEach like calling break?