These two functions, _.forEach and $.each, taken respectively from underscore and jQuery seems to make the same thing.
What are the possible reasons to prefer one implementation to the other?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
_.forEachand$.eachdiffers for the arguments passed to the callback.If you use
_.forEach, the first argument passed to the callback is the value, not the key.So if you don’t bother at all about the key you should use
_.forEach.Other differences:
_.forEachit will be a bit faster as it uses the nativeArrray.prototype.forEachin modern browsers.