*Chainable* Javascript method to do something for each item of an array

I’m looking for a semantic way to perform some step on each item in a Javascript array while in the middle of a method chain, since I can’t use forEach for whatever reason:

forEach() executes the callback function once for each array element; unlike map() or reduce() it always returns the value undefined and is not chainable. The typical use case is to execute side effects at the end of a chain.

Laravel Collections have each and tap which perform largely the same function.

I can just use map and return the original item at the end I suppose, but I was wondering if there was a more built-in method to do so.

28 thoughts on “*Chainable* Javascript method to do something for each item of an array”

  1. 637366 543817Hello! I could have sworn Ive been to this internet site before but following browsing by means of some of the post I realized it is new to me. Nonetheless, Im surely pleased I discovered it and Ill be book-marking and checking back frequently! 983837

  2. 15542 143710Oh my goodness! an excellent write-up dude. Thank you Nonetheless Im experiencing issue with ur rss . Do not know why Cannot register for it. Could there be any person acquiring identical rss difficulty? Anybody who knows kindly respond. Thnkx 881412

  3. 242323 38090Aw, this became an extremely good post. In thought I would like to set up writing like that furthermore – taking time and actual effort to create a great article but what / points I say I procrastinate alot via no means appear to get something completed. 47876


Leave a Comment