{"id":595,"date":"2023-06-20T05:08:08","date_gmt":"2023-06-20T05:08:08","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=595"},"modified":"2023-06-21T13:00:34","modified_gmt":"2023-06-21T13:00:34","slug":"difference-between-array-push-and-pop-explain-with-example","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/difference-between-array-push-and-pop-explain-with-example\/","title":{"rendered":"Difference between array PUSH and POP? explain with example"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/06\/image-8.png\" alt=\"\" class=\"wp-image-597\" width=\"524\" height=\"367\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/06\/image-8.png 350w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2023\/06\/image-8-300x210.png 300w\" sizes=\"auto, (max-width: 524px) 100vw, 524px\" \/><\/figure>\n\n\n\n<p>In programming, &#8220;push&#8221; and &#8220;pop&#8221; are operations commonly associated with the manipulation of data in a data structure called an array. Arrays are used to store collections of elements of the same type.<\/p>\n\n\n\n<p><strong>Push:<\/strong> The &#8220;push&#8221; operation adds an element to the end of an array, increasing its size by one. The new element is inserted at the last position, shifting any existing elements to accommodate the new one.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\nlet numbers = [1, 2, 3];\nconsole.log(numbers);  \/\/ Output: [1, 2, 3]\n\nnumbers.push(4);\nconsole.log(numbers);  \/\/ Output: [1, 2, 3, 4]\n\n\n\n<p>In this example, the <code>push<\/code> method is used to add the number 4 to the end of the <code>numbers<\/code> array. After the push operation, the array contains [1, 2, 3, 4].<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pop:<\/strong> The &#8220;pop&#8221; operation removes and returns the last element from an array, reducing its size by one. The element that is popped is permanently removed from the array.<\/li>\n<\/ul>\n\n\n\nlet numbers = [1, 2, 3, 4];\nconsole.log(numbers);  \/\/ Output: [1, 2, 3, 4]\n\nlet poppedElement = numbers.pop();\nconsole.log(numbers);           \/\/ Output: [1, 2, 3]\nconsole.log(poppedElement);     \/\/ Output: 4\n\n\n\n<p>In this example, the <code>pop<\/code> method is used to remove the last element (4) from the <code>numbers<\/code> array. The popped element is stored in the variable <code>poppedElement<\/code>. After the pop operation, the array contains [1, 2, 3], and the popped element is 4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In programming, &#8220;push&#8221; and &#8220;pop&#8221; are operations commonly associated with the manipulation of data in a data structure called an array. Arrays are used to store collections&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-595","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=595"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":598,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/595\/revisions\/598"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}