{"id":139,"date":"2022-11-24T07:51:26","date_gmt":"2022-11-24T07:51:26","guid":{"rendered":"http:\/\/javigomez.org\/?p=139"},"modified":"2025-09-29T20:34:30","modified_gmt":"2025-09-29T20:34:30","slug":"utilizacion-de-push-y-pop-con-array-en-javascript","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2022\/11\/24\/utilizacion-de-push-y-pop-con-array-en-javascript\/","title":{"rendered":"Utilizaci\u00f3n de push y pop con array en Javascript"},"content":{"rendered":"\n<p>Un ejemplo de utilizaci\u00f3n del push y el pop sobre un array en Javascript. Para la visualizaci\u00f3n de la informaci\u00f3n se utiliza ForEach.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"http:\/\/javigomez.org\/wp-content\/uploads\/2022\/11\/image-29-2-11-1.png\" alt=\"\" class=\"wp-image-140\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;title>4.5&lt;\/title>\n&lt;\/head>\n\n&lt;body>\n  &lt;h1>4.5&lt;\/h1>\n  &lt;p>Se introduce uno a uno elementos en un array y por otro lado, se van quitando&lt;\/p>\n  &lt;p>\n    Valor: &lt;input type=\"text\" placeholder=\"Texto a a\u00f1adir\" id=\"valor\">\n    &lt;button onclick=\"insertar()\">Insertar&lt;\/button>\n    &lt;button onclick=\"quitar()\">Quitar&lt;\/button>\n  &lt;\/p>\n\n  &lt;input type=\"button\" value=\"Reiniciar\" onclick=\"reiniciar()\">\n  &lt;p id=\"resultado\">&lt;\/p>\n\n  &lt;script>\n    var array = &#91;];\n\n    function quitar() {\n      <strong>array.pop();<\/strong>\n      document.getElementById(\"resultado\").innerHTML = \"\";\n     <strong> array.forEach(muestra);<\/strong>\n\n    }\n    function insertar() {\n      var txt = document.getElementById(\"valor\").value;\n      <strong>array.push(txt);<\/strong>\n\n      document.getElementById(\"resultado\").innerHTML = \"\";\n      <strong>array.forEach(muestra);<\/strong>\n    }\n    <strong>function muestra(ele, ind, arr)<\/strong> {\n      document.getElementById(\"resultado\").innerHTML +=  \"Ind:\" + ind + \" elemento: \" + ele + \"&lt;br>\";\n    }\n    function reiniciar() {\n      location.reload();\n    }\n\n  &lt;\/script>\n&lt;\/body>\n\n&lt;\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Un ejemplo de utilizaci\u00f3n del push y el pop sobre un array en Javascript. Para la visualizaci\u00f3n de la informaci\u00f3n se utiliza ForEach.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[40,163,204,266,274],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-array","tag-foreach","tag-javascript","tag-pop","tag-push"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":979,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/139\/revisions\/979"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}