{"id":1052,"date":"2022-07-21T09:04:43","date_gmt":"2022-07-21T09:04:43","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=1052"},"modified":"2022-07-21T09:04:45","modified_gmt":"2022-07-21T09:04:45","slug":"javascript-array-push","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/javascript-array-push\/","title":{"rendered":"Javascript Array Push() Method"},"content":{"rendered":"<p style=\"text-align: center;\"><strong>Javascript Array Push<\/strong><\/p>\n<p><span style=\"font-size: revert; background-color: var(--wp--preset--color--background); color: var(--wp--preset--color--foreground); font-family: var(--wp--preset--font-family--system-font);\">When we use the pop method, we are removing the last element from the array, and when we are using the push method, we are pushing some elements to the end of the array. So, a new element is added to the array, at the end, and the length of the array changes. This push method is going to return the new length of the array.<br \/>\n<\/span><\/p>\n<p><span style=\"font-size: revert; background-color: var(--wp--preset--color--background); color: var(--wp--preset--color--foreground); font-family: var(--wp--preset--font-family--system-font);\">This method returns the new length of the array.<br \/>\n<\/span><\/p>\n<p><span style=\"font-size: revert; background-color: var(--wp--preset--color--background); color: var(--wp--preset--color--foreground); font-family: var(--wp--preset--font-family--system-font);\">You can refer to the below code to understand the push property &#8211;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1054 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/05\/push-method.jpg\" alt=\"\" width=\"603\" height=\"104\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/05\/push-method.jpg 603w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/05\/push-method-300x52.jpg 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>As you can see in the above program, we have an array, and then we are trying to push some value (a string) to the array, so the new value would be pushed to the end, and the new length of the array is returned. Let&#8217;s have a look at the output now \u2192<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1055 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/05\/push-method-1.jpg\" alt=\"\" width=\"755\" height=\"111\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/05\/push-method-1.jpg 755w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/05\/push-method-1-300x44.jpg 300w\" sizes=\"auto, (max-width: 755px) 100vw, 755px\" \/><br \/>\nAs you can see, we could push the data &#8216;something&#8217;, onto the end of the array. The push method returns the new length of the array. You can try using the method for practice, so you can get familiar with it, and we can use this method as and when required.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Javascript Array Push When we use the pop method, we are removing the last element from the array, and when we are using the push method, we are pushing some elements to the end of the array. So, a new element is added to the array, at the end, and the length of the array [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[14,15],"class_list":{"0":"post-1052","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-javascript-tutorial","7":"tag-javascript","8":"tag-javascript-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=1052"}],"version-history":[{"count":5,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1052\/revisions"}],"predecessor-version":[{"id":2432,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/1052\/revisions\/2432"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}