<?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[Yogayata Verma]]></title><description><![CDATA[A web developer and continuous learner focused on understanding systems and sharing :)]]></description><link>https://yogayataverma.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1767069028908/b3166209-7991-4c9f-a724-c8f86f66671e.png</url><title>Yogayata Verma</title><link>https://yogayataverma.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 13:43:26 GMT</lastBuildDate><atom:link href="https://yogayataverma.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[JavaScript Array Methods for Beginners: push(), pop(), shift(), unshift(), map(), filter(), reduce(), and forEach()]]></title><description><![CDATA[When you start learning JavaScript, arrays quickly become part of everyday coding.
You use arrays to store lists of numbers, names, products, tasks, and much more. But just storing data is not enough ]]></description><link>https://yogayataverma.hashnode.dev/javascript-array-methods-for-beginners-push-pop-shift-unshift-map-filter-reduce-and-foreach</link><guid isPermaLink="true">https://yogayataverma.hashnode.dev/javascript-array-methods-for-beginners-push-pop-shift-unshift-map-filter-reduce-and-foreach</guid><dc:creator><![CDATA[Yogayata Verma]]></dc:creator><pubDate>Sun, 15 Mar 2026 13:25:53 GMT</pubDate><content:encoded><![CDATA[<p>When you start learning JavaScript, arrays quickly become part of everyday coding.</p>
<p>You use arrays to store lists of numbers, names, products, tasks, and much more. But just storing data is not enough — you also need ways to add, remove, update, and process that data.</p>
<p>That is where JavaScript array methods become super useful.</p>
<p>In this blog, we will understand some of the most beginner-friendly and commonly used array methods:</p>
<ul>
<li><p><code>push()</code> and <code>pop()</code></p>
</li>
<li><p><code>shift()</code> and <code>unshift()</code></p>
</li>
<li><p><code>map()</code></p>
</li>
<li><p><code>filter()</code></p>
</li>
<li><p><code>reduce()</code></p>
</li>
<li><p><code>forEach()</code></p>
</li>
</ul>
<p>I’ll explain each one with simple practical examples, show the array state before and after, and also compare traditional <code>for</code> loops with <code>map()</code> and <code>filter()</code>.</p>
<p>Let’s begin.</p>
<h2>Why learn array methods?</h2>
<p>Imagine you have a list of marks, product prices, or student names.</p>
<p>You may want to:</p>
<ul>
<li><p>add a new item</p>
</li>
<li><p>remove the last item</p>
</li>
<li><p>remove the first item</p>
</li>
<li><p>update every value</p>
</li>
<li><p>select only some values</p>
</li>
<li><p>calculate a total</p>
</li>
<li><p>print each value one by one</p>
</li>
</ul>
<p>Array methods make these tasks much easier and cleaner.</p>
<h2><code>push()</code> — Add element to the end</h2>
<p>The <code>push()</code> method adds one or more elements to the end of an array.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let fruits = ["apple", "banana"];

console.log("Before:", fruits);

fruits.push("mango");

console.log("After:", fruits);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Before: ["apple", "banana"]
After: ["apple", "banana", "mango"]
</code></pre>
<h3>Practical use case</h3>
<p>Suppose you are building a to-do app and a user adds a new task.  </p>
<p>You can use <code>push()</code> to add that task at the end of the list.</p>
<pre><code class="language-javascript">let tasks = ["Study JS", "Practice coding"];
tasks.push("Revise arrays");

console.log(tasks);
</code></pre>
<pre><code class="language-javascript">["Study JS", "Practice coding", "Revise arrays"]
</code></pre>
<h2><code>pop()</code> — Remove element from the end</h2>
<p>The <code>pop()</code> method removes the last element from an array.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let fruits = ["apple", "banana", "mango"];

console.log("Before:", fruits);

fruits.pop();

console.log("After:", fruits);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Before: ["apple", "banana", "mango"]
After: ["apple", "banana"]
</code></pre>
<h3>Practical use case</h3>
<p>You can think of this like removing the latest item from a cart or undoing the last step in a list.</p>
<h2><code>unshift()</code> — Add element to the beginning</h2>
<p>The <code>unshift()</code> method adds one or more elements to the beginning of an array.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let colors = ["blue", "green"];

console.log("Before:", colors);

colors.unshift("red");

console.log("After:", colors);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Before: ["blue", "green"]
After: ["red", "blue", "green"]
</code></pre>
<h3>Practical use case</h3>
<p>This is useful when you want the newest item to appear first, like showing the latest notification at the top.</p>
<h2><code>shift()</code> — Remove element from the beginning</h2>
<p>The <code>shift()</code> method removes the first element from an array.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let colors = ["red", "blue", "green"];

console.log("Before:", colors);

colors.shift();

console.log("After:", colors);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Before: ["red", "blue", "green"]
After: ["blue", "green"]
</code></pre>
<h3>Practical use case</h3>
<p>This can be helpful when processing a queue, where the first item should be removed first.</p>
<h2><code>forEach()</code> — Do something for every element</h2>
<p>The <code>forEach()</code> method runs a function for each element of an array.</p>
<p>It is mainly used when you want to loop through the array and perform an action, like printing values.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let numbers = [10, 20, 30];

numbers.forEach(function(num) {
  console.log(num);
});
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">10
20
30
</code></pre>
<h3>Practical use case</h3>
<p>If you want to display every username or print every score, <code>forEach()</code> is very handy.</p>
<pre><code class="language-javascript">let students = ["Aman", "Riya", "Kunal"];

students.forEach(function(student) {
  console.log("Welcome " + student);
});
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Welcome Aman
Welcome Riya
Welcome Kunal
</code></pre>
<h3>Important point</h3>
<p><code>forEach()</code> is great for doing something with each item, but it does <strong>not</strong> return a new transformed array like <code>map()</code>.</p>
<h2><code>map()</code> — Create a new array by transforming each element</h2>
<p>The <code>map()</code> method creates a <strong>new array</strong> by applying a function to every element of the original array.</p>
<p>This is one of the most useful methods in JavaScript.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4];

console.log("Original:", numbers);

let doubled = numbers.map(function(num) {
  return num * 2;
});

console.log("New array:", doubled);
console.log("Original after map:", numbers);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Original: [1, 2, 3, 4]
New array: [2, 4, 6, 8]
Original after map: [1, 2, 3, 4]
</code></pre>
<h3>What to notice?</h3>
<ul>
<li><p><code>map()</code> does not change the original array</p>
</li>
<li><p>it creates a brand new array</p>
</li>
<li><p>each element gets transformed</p>
</li>
</ul>
<h3>Practical example</h3>
<p>Suppose you have product prices and want to apply a 10 rupee increase to each price.</p>
<pre><code class="language-javascript">let prices = [100, 200, 300];

let updatedPrices = prices.map(function(price) {
  return price + 10;
});

console.log(updatedPrices);
</code></pre>
<pre><code class="language-javascript">[110, 210, 310]
</code></pre>
<h2>Traditional <code>for</code> loop vs <code>map()</code></h2>
<p>Let’s compare both.</p>
<h3>Using <code>for</code> loop</h3>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4];
let doubled = [];

for (let i = 0; i &lt; numbers.length; i++) {
  doubled.push(numbers[i] * 2);
}

console.log(doubled);
</code></pre>
<h3>Using <code>map()</code></h3>
<pre><code class="language-javascript">let numbers = [1, 2, 3, 4];

let doubled = numbers.map(function(num) {
  return num * 2;
});

console.log(doubled);
</code></pre>
<h3>Why <code>map()</code> feels cleaner</h3>
<p>With <code>map()</code>:</p>
<ul>
<li><p>less code</p>
</li>
<li><p>easy to read</p>
</li>
<li><p>directly shows that you are transforming data</p>
</li>
</ul>
<p>If your goal is “convert each item into something else,” <code>map()</code> is usually better.</p>
<h2><code>filter()</code> — Create a new array with selected elements</h2>
<p>The <code>filter()</code> method creates a new array containing only the elements that match a condition.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let numbers = [5, 12, 8, 20, 3];

console.log("Original:", numbers);

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

console.log("Filtered:", greaterThanTen);
console.log("Original after filter:", numbers);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">Original: [5, 12, 8, 20, 3]
Filtered: [12, 20]
Original after filter: [5, 12, 8, 20, 3]
</code></pre>
<h3>What to notice?</h3>
<ul>
<li><p><code>filter()</code> does not change the original array</p>
</li>
<li><p>it returns a new array</p>
</li>
<li><p>only elements that pass the condition stay in the new array</p>
</li>
</ul>
<h3>Practical example</h3>
<p>Suppose you want to show only students who passed.</p>
<pre><code class="language-javascript">let marks = [35, 80, 25, 90, 40];

let passed = marks.filter(function(mark) {
  return mark &gt;= 40;
});

console.log(passed);
</code></pre>
<pre><code class="language-javascript">[80, 90, 40]
</code></pre>
<h2>Traditional <code>for</code> loop vs <code>filter()</code></h2>
<h3>Using <code>for</code> loop</h3>
<pre><code class="language-javascript">let numbers = [5, 12, 8, 20, 3];
let result = [];

for (let i = 0; i &lt; numbers.length; i++) {
  if (numbers[i] &gt; 10) {
    result.push(numbers[i]);
  }
}

console.log(result);
</code></pre>
<h3>Using <code>filter()</code></h3>
<pre><code class="language-javascript">let numbers = [5, 12, 8, 20, 3];

let result = numbers.filter(function(num) {
  return num &gt; 10;
});

console.log(result);
</code></pre>
<h3>Why <code>filter()</code> is better here</h3>
<p>With <code>filter()</code>, the purpose is obvious:  </p>
<p>we are selecting values based on a condition.</p>
<h2><code>reduce()</code> — Turn the whole array into a single value</h2>
<p>The <code>reduce()</code> method is used when you want to take all array elements and combine them into one final result.</p>
<p>That final result can be:</p>
<ul>
<li><p>a sum</p>
</li>
<li><p>a total price</p>
</li>
<li><p>a count</p>
</li>
<li><p>a single object</p>
</li>
<li><p>many other things</p>
</li>
</ul>
<p>For beginners, the easiest example is finding the total sum of numbers.</p>
<h3>Example</h3>
<pre><code class="language-javascript">let numbers = [10, 20, 30];

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

console.log(total);
</code></pre>
<h3>Output</h3>
<pre><code class="language-javascript">60
</code></pre>
<h3>Beginner-friendly explanation</h3>
<p>Inside <code>reduce()</code>:</p>
<ul>
<li><p><code>accumulator</code> stores the running result</p>
</li>
<li><p><code>currentValue</code> is the current item from the array</p>
</li>
<li><p><code>0</code> is the starting value</p>
</li>
</ul>
<p>So this happens step by step:</p>
<ul>
<li><p>start with <code>0</code></p>
</li>
<li><p><code>0 + 10 = 10</code></p>
</li>
<li><p><code>10 + 20 = 30</code></p>
</li>
<li><p><code>30 + 30 = 60</code></p>
</li>
</ul>
<p>Final result: <code>60</code></p>
<h3>Simple real-life use case</h3>
<p>Suppose you have shopping prices and want the total bill.</p>
<pre><code class="language-javascript">let cartPrices = [199, 299, 499];

let totalBill = cartPrices.reduce(function(total, price) {
  return total + price;
}, 0);

console.log(totalBill);
</code></pre>
<pre><code class="language-javascript">997
</code></pre>
<h3>Keep this in mind</h3>
<p>At first, <code>reduce()</code> may feel a little confusing.  </p>
<p>That is completely normal.</p>
<p>Start by using it only for total sum. Once you get comfortable, then explore more advanced uses.</p>
<h2>Before and After Array State Summary</h2>
<p>Here’s a quick recap of how these methods affect arrays.</p>
<h3><code>push()</code></h3>
<pre><code class="language-javascript">Before: ["a", "b"]
After:  ["a", "b", "c"]
</code></pre>
<h3><code>pop()</code></h3>
<pre><code class="language-javascript">Before: ["a", "b", "c"]
After:  ["a", "b"]
</code></pre>
<h3><code>unshift()</code></h3>
<pre><code class="language-javascript">Before: ["b", "c"]
After:  ["a", "b", "c"]
</code></pre>
<h3><code>shift()</code></h3>
<pre><code class="language-javascript">Before: ["a", "b", "c"]
After:  ["b", "c"]
</code></pre>
<h3><code>map()</code></h3>
<pre><code class="language-javascript">Original: [1, 2, 3]
New:      [2, 4, 6]
</code></pre>
<h3><code>filter()</code></h3>
<pre><code class="language-javascript">Original: [5, 12, 8, 20]
New:      [12, 20]
</code></pre>
<h3><code>reduce()</code></h3>
<pre><code class="language-javascript">Original: [10, 20, 30]
Result:   60
</code></pre>
<h3><code>forEach()</code></h3>
<pre><code class="language-javascript">Original: [1, 2, 3]
Action: prints each value
</code></pre>
<h2>When should you use which method?</h2>
<p>Use:</p>
<ul>
<li><p><code>push()</code> when you want to add to the end</p>
</li>
<li><p><code>pop()</code> when you want to remove from the end</p>
</li>
<li><p><code>unshift()</code> when you want to add to the beginning</p>
</li>
<li><p><code>shift()</code> when you want to remove from the beginning</p>
</li>
<li><p><code>forEach()</code> when you want to do something with each item</p>
</li>
<li><p><code>map()</code> when you want to transform every item into a new array</p>
</li>
<li><p><code>filter()</code> when you want to keep only matching items</p>
</li>
<li><p><code>reduce()</code> when you want one final value from all items</p>
</li>
</ul>
<h2>Flowchart: How <code>map()</code> works</h2>
<pre><code class="language-markdown">Original array: [1, 2, 3]

1  ──transform──&gt; 2
2  ──transform──&gt; 4
3  ──transform──&gt; 6

New array: [2, 4, 6]
</code></pre>
<h2>Flowchart: How <code>filter()</code> works</h2>
<pre><code class="language-markdown">Original array: [5, 12, 8, 20]
Condition: value &gt; 10

5   ──&gt; No  ──&gt; skip
12  ──&gt; Yes ──&gt; keep
8   ──&gt; No  ──&gt; skip
20  ──&gt; Yes ──&gt; keep

New array: [12, 20]
</code></pre>
<h2>Simple visual for <code>reduce()</code> accumulating values</h2>
<pre><code class="language-markdown">Array: [10, 20, 30]

Start with accumulator = 0

0 + 10 = 10
10 + 20 = 30
30 + 30 = 60

Final result: 60
</code></pre>
<h2>Practice in browser console</h2>
<p>The best way to learn these methods is to try them yourself.</p>
<p>Open your browser console and test small examples like this:</p>
<pre><code class="language-javascript">let nums = [2, 4, 6, 8];

nums.push(10);
console.log(nums);

let doubled = nums.map(function(n) {
  return n * 2;
});
console.log(doubled);

let bigNums = nums.filter(function(n) {
  return n &gt; 5;
});
console.log(bigNums);
</code></pre>
<p>When you run code yourself, the concepts stay in your mind much better.</p>
<h2>Mini assignment for you</h2>
<p>Try this on your own.</p>
<h3>Step 1: Create an array of numbers</h3>
<pre><code class="language-javascript">let numbers = [4, 7, 12, 15, 3];
</code></pre>
<h3>Step 2: Use <code>map()</code> to double each number</h3>
<p>Expected idea:</p>
<pre><code class="language-javascript">[8, 14, 24, 30, 6]
</code></pre>
<h3>Step 3: Use <code>filter()</code> to get numbers greater than 10</h3>
<p>Expected idea:</p>
<pre><code class="language-javascript">[12, 15]
</code></pre>
<h3>Step 4: Use <code>reduce()</code> to calculate total sum</h3>
<p>Expected idea:</p>
<pre><code class="language-javascript">41
</code></pre>
<h3>Full practice solution</h3>
<pre><code class="language-javascript">let numbers = [4, 7, 12, 15, 3];

let doubled = numbers.map(function(num) {
  return num * 2;
});

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

let total = numbers.reduce(function(sum, num) {
  return sum + num;
}, 0);

console.log("Original:", numbers);
console.log("Doubled:", doubled);
console.log("Greater than 10:", greaterThanTen);
console.log("Total sum:", total);
</code></pre>
<h2>Final thoughts</h2>
<p>Array methods are one of the most important parts of JavaScript.</p>
<p>If you are a beginner, focus first on understanding:</p>
<ul>
<li><p>what each method does</p>
</li>
<li><p>whether it changes the original array or creates a new one</p>
</li>
<li><p>when to use it in real projects</p>
</li>
</ul>
<p>A good learning order is:</p>
<ol>
<li><p><code>push()</code> / <code>pop()</code></p>
</li>
<li><p><code>shift()</code> / <code>unshift()</code></p>
</li>
<li><p><code>forEach()</code></p>
</li>
<li><p><code>map()</code></p>
</li>
<li><p><code>filter()</code></p>
</li>
<li><p><code>reduce()</code></p>
</li>
</ol>
<p>Do not worry about chaining methods right now.  </p>
<p>First become comfortable using each one individually.</p>
<p>Once these basics become clear, your JavaScript code will start looking much cleaner and more professional.</p>
<h2>Quick challenge</h2>
<p>Take this array:</p>
<pre><code class="language-javascript">let nums = [1, 5, 10, 20];
</code></pre>
<p>Try to do these yourself:</p>
<ul>
<li><p>add <code>50</code> at the end</p>
</li>
<li><p>remove the first element</p>
</li>
<li><p>create a new array with all values tripled</p>
</li>
<li><p>create another array with only values greater than <code>10</code></p>
</li>
<li><p>find the total sum</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Hi, I’m Yogayata Verma - A Learner and A Builder]]></title><description><![CDATA[Hi 👋
I am Yogayata Verma, a professional web developer. Every day, I dive a bit deep into concepts, learn from my flaws, and take steps forward.
A Little About My Background
I’ve been working as a Web Developer and have experience with:

frontend an...]]></description><link>https://yogayataverma.hashnode.dev/hi-im-yogayata-verma-a-learner-and-a-builder</link><guid isPermaLink="true">https://yogayataverma.hashnode.dev/hi-im-yogayata-verma-a-learner-and-a-builder</guid><category><![CDATA[aboutme]]></category><dc:creator><![CDATA[Yogayata Verma]]></dc:creator><pubDate>Mon, 29 Dec 2025 18:17:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1767435854719/995bd790-fbfb-4708-8992-d9ef6e7b5227.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi 👋</p>
<p>I am Yogayata Verma, a professional web developer. Every day, I dive a bit deep into concepts, learn from my flaws, and take steps forward.</p>
<h2 id="heading-a-little-about-my-background">A Little About My Background</h2>
<p>I’ve been working as a <strong>Web Developer</strong> and have experience with:</p>
<ul>
<li><p>frontend and backend development</p>
</li>
<li><p>APIs and databases</p>
</li>
<li><p>microservices and system design</p>
</li>
<li><p>integrating AI and third-party services</p>
</li>
</ul>
<p>I’ve worked on projects related to:</p>
<ul>
<li><p>healthcare systems</p>
</li>
<li><p>real-time chat applications</p>
</li>
<li><p>online counselling platforms</p>
</li>
<li><p>dashboards and analytics tools</p>
</li>
</ul>
<h2 id="heading-my-learning-philosophy">My Learning Philosophy</h2>
<p>I strongly believe in:</p>
<ul>
<li><p>understanding over memorizing</p>
</li>
<li><p>consistency over speed</p>
</li>
<li><p>curiosity over fear</p>
</li>
<li><p>more knowledge, more power</p>
</li>
</ul>
<p>I focus on building <strong>strong fundamentals</strong>, because frameworks change, concepts don’t.</p>
<h2 id="heading-final-note">Final Note</h2>
<p>Let us learn together, one concept at a time.</p>
<p>— <strong>Yogayata Verma</strong></p>
<h2 id="heading-reach-out">Reach Out :)</h2>
<div class="hn-embed-widget" id="7"></div>]]></content:encoded></item></channel></rss>