I am not able to understand the difference between underscore js methods _.each and _.invoke.
Both seems to invoke the function passed on each item.
Under which scenario shall I use _.each and _.invoke?
Please share the difference with some examples.
No, they do different things. Have a look at their code!
eachcalls a given function with each element of a given object. You can additionally pass it a context on which the functions are applied. It acts like the nativeforEachon arrays.It does return undefined.
invokeusually gets a method name as a string, and looks up the method dynamically for each element of the given set. Then it applies the method on that element; and you additionally can pass it some arguments.It does return the results of the invocations, it basically does
map.