<?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: elam0012</title>
    <description>The latest articles on DEV Community by elam0012 (@elam0012).</description>
    <link>https://dev.to/elam0012</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F720683%2Fc668f810-74ab-46da-b984-8f2e1d762590.jpeg</url>
      <title>DEV Community: elam0012</title>
      <link>https://dev.to/elam0012</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/elam0012"/>
    <language>en</language>
    <item>
      <title>Array.prototype.pop(), push(), shift(), and unshift()</title>
      <dc:creator>elam0012</dc:creator>
      <pubDate>Tue, 12 Oct 2021 02:29:31 +0000</pubDate>
      <link>https://dev.to/elam0012/array-prototype-pop-push-shift-and-unshift-311h</link>
      <guid>https://dev.to/elam0012/array-prototype-pop-push-shift-and-unshift-311h</guid>
      <description>&lt;p&gt;In this tutorial I am going to cover an important topic regarding different Array’s methods that a lot of us get confused when using it. I am going to cover the difference between pop(), push(), shift(), and unshift().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Pop( ):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;pop() is an array method will return the last element in the array and actually delete it from the array, which will decrease the elements length by 1. If the array has only one Element, then the returned value will be “undefined”. This method can be used either with array of variables or Array of objects. The method Syntax is pop( ).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gre36dfw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sz5ai3gwasvw0a45wlia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gre36dfw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sz5ai3gwasvw0a45wlia.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zt9dbugD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxwpyj9qiw7gfw8eahpf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zt9dbugD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxwpyj9qiw7gfw8eahpf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Push( ):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unlike pop(), the push( ) method will insert a new element(s) to the Array and place it at its end, and will return the new Array length. This will increase the Array length by adding the number of the inserted elements to the number of the original Array’s element(s) length. Means it can push only single element or number of elements at once. And like pop(), this method can be used either with array of variables or Array of objects The method Syntax is push(element0, …, elementN  ).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nz-D9SXy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ij7f0gs5noatu83mia6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nz-D9SXy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ij7f0gs5noatu83mia6b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YX2J8ui4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cg2zflghxxg5c30y9fv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YX2J8ui4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cg2zflghxxg5c30y9fv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.shift( ):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Opposite to pop( ), The shift( ) method will return the first element in the array and also delete it from the array. This will decrease the elements length by 1. If the array has only one Element, then the returned value will be “undefined”. This method can be used either with array of variables or Array of objects. The method Syntax is shift( ).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h2wJpDQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cw0lfs8qquadiqkmrx1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h2wJpDQi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cw0lfs8qquadiqkmrx1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JAc2I6dc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/odif8mfoh7k4mns504p4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JAc2I6dc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/odif8mfoh7k4mns504p4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.unshift( ):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;unshift( ) method will insert a new element(s) to the Array and place it at its beginning. It will return the new Array length. The method will increase the Array length by adding the number of the inserted elements to the number of the original Array’s element(s) length. Means it can add only single element or number of elements at once. And again, this method can be used either with array of variables or Array of objects The method Syntax is unshift(element0, …, elementN  ).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v9EDv3cT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgq6dbshgsv0ghbkkbi7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v9EDv3cT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgq6dbshgsv0ghbkkbi7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qpmWE48b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/empozgfhp23m8b59xxyk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qpmWE48b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/empozgfhp23m8b59xxyk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
