<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shivang Chauhan on Medium]]></title>
        <description><![CDATA[Stories by Shivang Chauhan on Medium]]></description>
        <link>https://medium.com/@shivang7?source=rss-472ad06560d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2jNkZ41zfWCoPqlHYeBuug.jpeg</url>
            <title>Stories by Shivang Chauhan on Medium</title>
            <link>https://medium.com/@shivang7?source=rss-472ad06560d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:26:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivang7/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[5 most used Javascript array methods]]></title>
            <link>https://shivang7.medium.com/5-most-used-javascript-array-methods-4e5ae38e1ceb?source=rss-472ad06560d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5ae38e1ceb</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Shivang Chauhan]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 05:16:49 GMT</pubDate>
            <atom:updated>2022-10-12T05:16:49.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*80M3hnLtMifbOoJTHD42NA.jpeg" /></figure><p>I will go through some of the Javascript methods which I use most and that I absolutely love to use in my day-to-day Javascript coding.</p><p>Please note that this list is compiled based on my personal experience and it may be different for other people.</p><p>So without delaying more let’s go through the list, I will explain what each of the methods does with an example and then explain what is going on in the example as well.</p><h3>Using Array Filter()</h3><p>This method is one of the most used methods in Javascript and I also use it almost daily when I want to filter an array or remove any element from an array, let’s understand this method using an example.</p><pre>const numbers = [1, 2, 3, 4, 5];<br>const modifiedArr = numbers.filter((el) =&gt; el !== 2);<br>console.log(modifiedArr); // [1, 3, 4, 5]</pre><h3>Explanation</h3><p>Let’s try to understand this, this method takes a callback function as an argument and this callback function gets called with a condition of our choice, each element in an array gets checked for that condition, if the element matches the condition the callback function returns true and otherwise false.</p><p>If the callback function returns true that array element gets pushed in a new array and in case of false that element gets skipped and doesn&#39;t gets added to the new array.</p><h3>Array forEach()</h3><p>I think most of the people who don’t even use Javascript know about this famous method, which is basically used to loop through an array, let’s see with an example.</p><pre>const arr = [1, 2, 3, 4, 5];</pre><pre>arr.forEach((el, index, array) =&gt; console.log(&#39;element&#39;, el, &#39;index&#39;, index, &#39;arr&#39;, array);</pre><pre>// output<br>// element 1 index 0 arr (5) [1, 2, 3, 4, 5]<br>// element 2 index 1 arr (5) [1, 2, 3, 4, 5]<br>// element 3 index 2 arr (5) [1, 2, 3, 4, 5]<br>// element 4 index 3 arr (5) [1, 2, 3, 4, 5]<br>// element 5 index 4 arr (5) [1, 2, 3, 4, 5]</pre><h3>Explanation</h3><p>This method accepts a callback function as an argument that gets called for each element in an array, this callback function accepts up to three arguments.</p><p>The first argument is the element itself for which the callback function is executing, the next argument is the index position of that element and the last argument is the copy of the whole array on which forEach is being executed.</p><h3>Array map()</h3><p>I use this method mostly on the frontend side with ReactJs, whenever I want to map any element for an array, but this can be used in the backend as well with NodeJs, let’s see an example.</p><pre>const arr = [{ name: &#39;John&#39;, age: 18 }, { name: &#39;Max&#39;, age: &#39;20&#39; }];</pre><pre>const names = arr.map((el) =&gt; el.name);</pre><pre>console.log(&#39;names&#39;, names); // names [&#39;John&#39;, &#39;Max&#39;]</pre><h3>Explanation</h3><p>This method also accepts a callback function and returns a new array, this callback function gets executed for each element in an array and whatever value is returned from this callback function gets pushed into the new array.</p><p>In our example, we are just mapping through an array of objects and creating an array of only names using map().</p><h3>Array find()</h3><p>I use this method to find out if any particular value is present in an array, let’s see an example of this</p><pre>const arr = [2, 3, 5, 6, 8];</pre><pre>const val = arr.find((el) =&gt; el % 2 === 0)</pre><pre>console.log(&#39;val&#39;, val); // val 2</pre><h3>Explanation</h3><p>This method also accepts a callback function and this callback function starts getting executed on the elements as soon as any element matches the condition defined inside the callback function, the execution stops and that particular element gets returned.</p><p>If no element matches the condition then undefined gets returned.</p><h3>Array reduce()</h3><p>I use this method whenever I want to do some calculation by using the current and previous element of an array and keep doing this for all the elements and get a single result in return, let’s try to see this through an example.</p><pre>const arr = [2, 2, 2, 2, 2];<br>const result = arr.reduce((prev, current) =&gt; prev * current);</pre><pre>console.log(&#39;result&#39;, result) // result 32</pre><h3>Explanation</h3><p>The reducer callback function gets called with the return of the previous calculation with elements and the current element in an array and it returns a single value.</p><p>For the first iteration if no default value is being passed then the first element of the array gets used as the previous value.</p><h3>Conclusion</h3><p>So these are the methods that I use very frequently and I love using these methods because they are so intuitive to me, I guess you also use these methods a lot.</p><p>Let me know in the comments section among these which one you use the most and which one is your favorite to work with.</p><p><em>Do leave your feedback in the comment section, and follow me for more content like this.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5ae38e1ceb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>