<?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"><channel><title><![CDATA[AyushCode]]></title><description><![CDATA[AyushCode]]></description><link>https://blog.ayushcode.me</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1593680282896/kNC7E8IR4.png</url><title>AyushCode</title><link>https://blog.ayushcode.me</link></image><generator>RSS for Node</generator><lastBuildDate>Sat, 06 Jun 2026 13:19:21 GMT</lastBuildDate><atom:link href="https://blog.ayushcode.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Top JavaScript Array Methods Every Beginner Should Know]]></title><description><![CDATA[When I first started learning JavaScript, I felt array methods were quite confusing, as there were many of them. But after practicing with some examples, I realised that array methods makes the code v]]></description><link>https://blog.ayushcode.me/top-javascript-array-methods-every-beginner-should-know</link><guid isPermaLink="true">https://blog.ayushcode.me/top-javascript-array-methods-every-beginner-should-know</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[coding]]></category><category><![CDATA[webdevelopment]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[#learning-in-public]]></category><dc:creator><![CDATA[Ayush Kumar]]></dc:creator><pubDate>Sat, 06 Jun 2026 10:37:29 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6957b06e6e38b6011157e5c8/feca6202-9a45-4100-95d8-cf805026ce1c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When I first started learning JavaScript, I felt array methods were quite confusing, as there were many of them. But after practicing with some examples, I realised that array methods makes the code very cleaner and readable.</p>
<p>In this blog, we will learn the important Javascript array methods that are used most of the time.</p>
<h2>Why do We Need Array Method?</h2>
<p>Without array methods, If we need to perform operations on a particular or all the elements of an array, we will have to use a for loop:</p>
<p>For example:</p>
<pre><code class="language-javascript">let arr = [1, 2, 3, 4];
for (let i = 0; i &lt; arr.length; i++) {
  arr[i] *= 2;
}

console.log(arr);  // Output : [2, 4, 6, 8]
</code></pre>
<p>This works, but array methods are very much shorter, cleaner, and more readable.</p>
<h2>1. push() and pop() :-</h2>
<ul>
<li><p>Both are used to manipulate the data at the end of an array. They <strong>mutates the original array</strong></p>
</li>
<li><p>push() is used to add an element at the last of an array.</p>
</li>
<li><p>pop() is used to remove an element from the last of an array.</p>
</li>
</ul>
<p>For Example:</p>
<pre><code class="language-javascript">//Push.....

const fruits = ["apple", "banana"]; 
fruits.push("mango"); 
console.log(fruits);

// Output : ["apple", "banana", "mango"]

//Pop.....

fruits.pop();
console.log(fruits);

// Output : ["apple", "banana",]
</code></pre>
<h2>2. shift() and unshift() :-</h2>
<ul>
<li><p>Both are used to manipulate the data at the beginning of an array. they <strong>mutate the original array</strong></p>
</li>
<li><p>shift() is used to add an element at the start of an array.</p>
</li>
<li><p>unshift() is used to remove an element from the start of an array (first element).</p>
</li>
</ul>
<p>For Example:</p>
<pre><code class="language-javascript">//shift().....

const fruits = ["apple", "banana"]; 
fruits.shift("mango"); 
console.log(fruits);

// Output : ["mango", "apple", "banana"]

//unshift.....

fruits.pop();
console.log(fruits);

// Output : ["apple", "banana"]
</code></pre>
<h2>3. map() :-</h2>
<p>Map is used to mutate every element of an array, for example, doubling each element of the array, etc</p>
<p>Map <strong>returns a brand new array</strong> consisting of the elements which result from the calling of the callback function for each element in the original array</p>
<p>For Example:</p>
<pre><code class="language-javascript">const arr = [1, 2, 3, 4];

const doubled = arr.map(function (num) {
  return num * 2;
});

console.log(doubled);

//Output: [2, 4, 6, 8]
</code></pre>
<h2>4. filter() :-</h2>
<p>As the name suggests, it is used to filter the elements of on array based on a given condition. It <strong>returns a brand new array</strong> consisting of the elements that satisfied a given condition.</p>
<p>For Example:</p>
<pre><code class="language-javascript">
const numbers = [5, 10, 15, 20];

const greaterThanTen = numbers.filter(function (num) {
  return num &gt; 10;
});

console.log(greaterThanTen);




Output

[15, 20]

Visual Flow

 [5, 10, 15, 20]
        ↓
keep numbers &gt; 10
        ↓
    [15, 20]
</code></pre>
<h2>5. reduce() :-</h2>
<ul>
<li><p><code>reduce()</code> is used to combine all array values into a single value.</p>
</li>
<li><p>It may feel confusing at first, so start with simple examples.</p>
</li>
</ul>
<p>Example: Find Sum of Numbers</p>
<pre><code class="language-javascript">const numbers = [1, 2, 3, 4];

const total = numbers.reduce(function (accumulator, currentValue) {
  return accumulator + currentValue;
}, 0);

console.log(total);
</code></pre>
<p>Output</p>
<pre><code class="language-plaintext">10
</code></pre>
<h3>How reduce() Works</h3>
<pre><code class="language-plaintext">0 + 1 = 1
1 + 2 = 3
3 + 3 = 6
6 + 4 = 10
</code></pre>
<p>Final Answer = <code>10</code></p>
<h2>6. forEach :-</h2>
<ul>
<li><p>forEach() is used to loop over each element of an array and perform the required action.</p>
</li>
<li><p>Unlike map, it does not return anything.</p>
</li>
</ul>
<p>Example</p>
<pre><code class="language-javascript">const fruits = ["apple", "banana", "mango"];

fruits.forEach(function (fruit) {
  console.log(fruit);
});

// Output

apple
banana
mango
</code></pre>
<p>Use <code>forEach()</code> when you only want to perform actions like printing values.</p>
<h2>Small Practice Assignment</h2>
<p>Try this yourself in the browser console.</p>
<p>Step 1: Create an array</p>
<pre><code class="language-javascript">const numbers = [2, 5, 8, 12];
</code></pre>
<p>Step 2: Double each number using map()</p>
<pre><code class="language-javascript">const doubled = numbers.map((num) =&gt; num * 2);

console.log(doubled);
</code></pre>
<p>Step 3: Get numbers greater than 10 using filter()</p>
<pre><code class="language-javascript">const greaterThanTen = numbers.filter((num) =&gt; num &gt; 10);

console.log(greaterThanTen);
</code></pre>
<p>Step 4: Find total sum using reduce()</p>
<pre><code class="language-javascript">const total = numbers.reduce((acc, curr) =&gt; acc + curr, 0);

console.log(total);
</code></pre>
<hr />
<h2>Final Thoughts</h2>
<p>Array methods are extremely useful in JavaScript in modern web development.</p>
<p>At first, reduce() and filter() might feel a little difficult, but after practicing a few examples, it will become much easier</p>
<p>The more you practice, the more natural these methods will feel.</p>
<p>Happy Coding</p>
]]></content:encoded></item></channel></rss>