How to iterate a JavaScript array using lodash - Kevin Chisholm Video

preview_player
Показать описание

Video Transcription:

In this video I’ll show you how to iterate a JavaScript array using lodash.



So this function is going to execute for every element of the array. The function’s going to execute, in this case, five times. And that way, here, instead of saying days i, I can just say day. Every time it executes I get a day, and a day is, first going to be Monday, then Tuesday, and Wednesday, and so forth. And for each iteration of this function, I’m just using day to create a list item and append that list item to this list right here, and that’s how I want to put this list of the five days.

If I added let’s say another day here… and let’s say I added Saturday, then we would see Saturday at the end of the list.

So the main thing is that the lodash for each method allows you to iterate over an array very simply, by passing it two arguments, the first is the actual array, and then a function that you would like executed for each element of the array, and that function receives the element as being iterated, over as its first argument.

If you found this video helpful, you can subscribe to my channel by clicking the red "Subscribe" button right under the video. You can also take a look at my blog, where there are many articles and tutorials about web development.

Thanks very much for watching.
Рекомендации по теме
visit shbcf.ru