JavaScript Array Map Method In 90 Seconds #JavaScriptJanuary
Watch the entire #JavaScriptJanuary series from the beginning!
The JavaScript array map() method creates a new array from the results of a function called on each element in another array. And it does not modify the original array.
The new array is equal to the original array mapped to a function. The function is passed as an argument to map and is called on each element in the original array. The function has access to the current element, the index, as well as the entire original array.
In the body of the function, the goal is to compute a new value and then return it. We can also change this into an arrow function to further reduce the amount of code. So by using map, we achieve our goal using much less code than a for loop and without mutating the internal state.
Note that since map builds a new array, using it when you aren’t using the returned array is an anti-pattern. So you shouldn’t use the map method if you’re not using the array it returns, nor when you’re not returning a value from the callback. In these cases it would be better to use forEach() or a regular for loop instead.
I’ll be releasing a new video every day in January! Stay tuned..
_____________________________________
📚 Learn to CODE in just a FEW months here:
Treehouse Discount Code: https://treehouse.7eer.net/codeSTACKr
_____________________________________
🛠️ Tools I use:
🟠 Theme: https://marketplace.visualstudio.com/items?itemName=codestackr.codestackr-theme
🟠 Font: STACKr Code (Exclusive to my VS Code Course – https://vsCodeHero.com)
🟠 SuperHero Extension Pack: https://marketplace.visualstudio.com/items?itemName=codeSTACKr.superhero-extensions
🤖 I now use AI-powered code completions thanks to Kite. You should too so grab it FREE: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=codestackr&utm_content=description-only
_____________________________________
💖 Show support!
PayPal: https://paypal.me/codeSTACKr
_____________________________________
Watch Next:
Web Development – Beginners Roadmap (2020) – https://youtu.be/iogabydg2y0
Playlist: Web Development For Beginners – https://www.youtube.com/watch?v=Ez4yHS2dsN8&list=PLkwxH9e_vrAJ0WbEsFA9W3I1W-g_BTsbt
_____________________________________
Connect With Me:
Website: http://www.codestackr.com
Twitter: https://twitter.com/codeSTACKr
Instagram: https://instagram.com/codeSTACKr/
Facebook: https://facebook.com/codeSTACKr
_____________________________________
** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.
#JavaScriptJanuary #31Days31Videos #codeSTACKr
source