<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Benjamin Alan Murphy-Kane</title>
    <description>The latest articles on DEV Community by Benjamin Alan Murphy-Kane (@benjaminkane03).</description>
    <link>https://dev.to/benjaminkane03</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F838876%2F34b9df86-d4d9-4774-b6ed-ffe0112b2383.png</url>
      <title>DEV Community: Benjamin Alan Murphy-Kane</title>
      <link>https://dev.to/benjaminkane03</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/benjaminkane03"/>
    <language>en</language>
    <item>
      <title>.forEach vs .map: A Short Summary</title>
      <dc:creator>Benjamin Alan Murphy-Kane</dc:creator>
      <pubDate>Wed, 30 Mar 2022 17:05:22 +0000</pubDate>
      <link>https://dev.to/benjaminkane03/foreach-vs-map-a-short-summary-e8h</link>
      <guid>https://dev.to/benjaminkane03/foreach-vs-map-a-short-summary-e8h</guid>
      <description>&lt;p&gt;Two very important array iteration methods that you will be seeing when using java are .forEach and .map, both going through an array and enacting a function on each element. But how do they differ in usage and purpose? In this post, I will be explaining key differences and elements that differ these two methods.&lt;/p&gt;

&lt;p&gt;First is &lt;em&gt;.forEach&lt;/em&gt;, an iteration method that will call a function for each element in an array. One important thing to note is that &lt;em&gt;.forEach&lt;/em&gt; will go through every single element in the array it is used on without mutating it. There are three five parameters to use in &lt;em&gt;.forEach&lt;/em&gt;, with two of them being required to run the function, these two being the function that is going to be run onto the array and &lt;em&gt;currentValue&lt;/em&gt;, the value/array that the function is being run on.&lt;/p&gt;

&lt;p&gt;The three optional parameters here are the index of the current element &lt;em&gt;index&lt;/em&gt;, the array of the current element if you are working on something that is nested, &lt;em&gt;arr&lt;/em&gt; and &lt;em&gt;thisValue&lt;/em&gt; which will pass the parameter entered as its &lt;em&gt;this&lt;/em&gt; value.&lt;/p&gt;

&lt;p&gt;Moving onto &lt;em&gt;.map&lt;/em&gt;, &lt;em&gt;.map&lt;/em&gt; will, just like .forEach, call a function onto an array, but the real question is... which array? To which I answer, a copy, of course!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;.map&lt;/em&gt; creates a copy of the original array and calls a function onto every element in said copy. One difference that stands out from &lt;em&gt;.forEach&lt;/em&gt; is that &lt;em&gt;.forEach&lt;/em&gt; creates a copy of the array, which is useful for preventing accidental mutations or changes in the array. And while I said earlier that &lt;em&gt;.forEach&lt;/em&gt; doesn't change the array, that was a bit of a lie. Any callback function provided in &lt;em&gt;.forEach&lt;/em&gt;'s parameter may cause a mutation depending on what you want the function to do.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;.map&lt;/em&gt; takes the same parameters as &lt;em&gt;.forEach&lt;/em&gt;, which at first fooled me when I was in the process of learning iteration methods for arrays. Understand that when you use &lt;em&gt;.map&lt;/em&gt;, the array that you iterate over is a copy of the original, preventing the data modified from being applied to the original array and returning that modified copy, whereas &lt;em&gt;.forEach.&lt;/em&gt; iterates the function over that exact array.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>.forEach vs .map</title>
      <dc:creator>Benjamin Alan Murphy-Kane</dc:creator>
      <pubDate>Tue, 29 Mar 2022 17:22:31 +0000</pubDate>
      <link>https://dev.to/benjaminkane03/foreach-vs-map-8ci</link>
      <guid>https://dev.to/benjaminkane03/foreach-vs-map-8ci</guid>
      <description>&lt;p&gt;Working with JavaScript, especially starting out, has been quite the challenge. An entertaining one at that, but definitely quite an endeavor. To start off my beautiful blogging journey, what better a way to start of then explaining two array-manipulation techniques?&lt;/p&gt;

&lt;p&gt;Let's start of with .forEach, a function that allows the user to transverse through an array and issue a callback function once for each element in an array. It does this in the order of the array, executing each element one at a time.&lt;/p&gt;

&lt;p&gt;And for the second we have .map, which creates a new version of an array for you to execute a function on. Similar to .forEach, it will call a function on each element in the array.&lt;/p&gt;

&lt;p&gt;In short, one large difference that took me one whole hour to internally process, is that .forEach will affect the original array and not return anything, whereas .map will create a new array that is a copy of the original to execute the function on and return the new array.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
