{"id":50407,"date":"2020-09-28T03:01:08","date_gmt":"2020-09-27T17:01:08","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=50407"},"modified":"2020-09-27T17:11:03","modified_gmt":"2020-09-27T07:11:03","slug":"javascript-array-method-stack-and-queue-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-array-method-stack-and-queue-tutorial\/","title":{"rendered":"Javascript Array Method Stack and Queue Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Array Method Stack and Queue Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work_stackqueue.jpg\" title=\"Javascript Array Method Stack and Queue Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Array Method Stack and Queue Tutorial<\/p><\/div>\n<p>The arrays involved in yesterday&#8217;s <a title='Javascript Array Method Solar System Planets Game Tutorial' href='#jamsspgt'>Javascript Array Method Solar System Planets Game Tutorial<\/a> can represent &#8220;order&#8221; where once there was none.  And in inventory control, how you organize inventory pricing can use arrays in a &#8230;<\/p>\n<ul>\n<li>FIFO way &#8230; like a queue &#8230; First In, First Out<\/li>\n<li>LIFO way &#8230; like a stack &#8230; Last In, First Out<\/li>\n<\/ul>\n<p> &#8230; and we demonstrate some such scenarios with <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html--GETME\">our changed<\/a> inhouse HTML\/CSS\/Javascipt client side <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html--GETME\">array_work.html<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html\">live run<\/a> link you can try, also, below, as &#8230;<\/p>\n<table style=width:100%;>\n<tr>\n<th>Number Queue scenario (where Ticket Number creation uses <a target=_blank title='Javascript array push method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_push.asp'>push<\/a> and Ticket Service uses <a target=_blank title='Javascript array shift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_shift.asp'>shift<\/a>) &#8230;<\/th>\n<\/tr>\n<tr>\n<td>\n<iframe style=\"width:100%;height:800px;\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html?nq=y\"><\/iframe>\n<\/td>\n<\/tr>\n<tr>\n<th>Card Stack scenario (where Card shuffling uses <a target=_blank title='Javascript array unshift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_unshift.asp'>unshift<\/a> and Card dealing uses <a target=_blank title='Javascript array shift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_shift.asp'>shift<\/a>) &#8230;<\/th>\n<\/tr>\n<tr>\n<td>\n<iframe style=\"width:100%;height:800px;\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html?cs=y\"><\/iframe>\n<\/td>\n<\/tr>\n<\/table>\n<p> &#8230; hopefully to get your &#8220;imagination juices&#8221; flowing!<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/new-javascript-array-method-solar-system-planets-game-tutorial\/'>New Javascript Array Method Stack and Queue Tutorial<\/a>.<\/p-->\n<hr>\n<p id='jamsspgt'>Previous relevant <a target=_blank title='Javascript Array Method Solar System Planets Game Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/javascript-array-method-solar-system-planets-game-tutorial\/'>Javascript Array Method Solar System Planets Game Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Array Method Solar System Planets Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work_game.jpg\" title=\"Javascript Array Method Solar System Planets Game Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Array Method Solar System Planets Game Tutorial<\/p><\/div>\n<p>You learn something, then you apply it in a game.  Sounds good, huh?<\/p>\n<p>There is nothing like applying your knowledge close to when you learn it, for that information to take hold.  And for it to be instinctual, perhaps a game where &#8230;<\/p>\n<ul>\n<li>Number of goes &#8230; and &#8230;<\/li>\n<li>Number of seconds elapsed<\/li>\n<\/ul>\n<p> &#8230; can help cement that knowledge in your brain.  We think so.  And so we have a &#8220;Solar System Planets Game&#8221; part to our web application of yesterday&#8217;s <a title='Javascript Array Method Primer Tutorial' href='#jampt'>Javascript Array Method Primer Tutorial<\/a> for you to try, optionally <font size=1><a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=T3YK95jW5p0#9x_FzCWl2nc'>that is<\/a><\/font>.<\/p>\n<p>The game goes &#8230;<\/p>\n<ul>\n<li>you are presented with an initial &#8220;Work on&#8221; names array such as &#8230;<br \/>\n<code><br \/>\nvar names = [\"Neptune\", \"Venus\", \"Uranus\"];<br \/>\n<\/code> &#8230; <\/li>\n<li>and you use your skills with &#8230;\n<ul>\n<li><a target=_blank title='Javascript array push method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_push.asp'>push<\/a><\/li>\n<li><a target=_blank title='Javascript array pop method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_pop.asp'>pop<\/a><\/li>\n<li><a target=_blank title='Javascript array shift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_shift.asp'>shift<\/a><\/li>\n<li><a target=_blank title='Javascript array unshift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_unshift.asp'>unshift<\/a><\/li>\n<\/ul>\n<p> &#8230;<\/li>\n<li>to turn that into a <strike>sow&#8217;s ear<\/strike>names array that look like &#8230;<br \/>\n<code><br \/>\nnames = [\"Mercury\", \"Venus\", \"Earth\",\"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\", \"Pluto\"];<br \/>\n<\/code> &#8230;<\/li>\n<li>to assess your &#8220;Goes \/ Time&#8221; score against previous attempts if that is how you roll?!<\/li>\n<\/ul>\n<p><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html-GETME\">Our changed<\/a> inhouse HTML\/CSS\/Javascipt client side <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html-GETME\">array_work.html<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html?sspg=y\">Solar Systems Planet Game<\/a> link you can try, also, below &#8230;<\/p>\n<p><iframe style=\"width:100%;height:800px;\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html?sspg=y\"><\/iframe><\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/javascript-array-method-solar-system-planets-game-tutorial\/'>Javascript Array Method Solar System Planets Game Tutorial<\/a>.<\/p-->\n<hr>\n<p id='jampt'>Previous relevant <a target=_blank title='Javascript Array Method Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/javascript-array-method-primer-tutorial\/'>Javascript Array Method Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Array Method Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.jpg\" title=\"Javascript Array Method Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Array Method Primer Tutorial<\/p><\/div>\n<p>If you are interested in writing your own web applications, on the &#8220;client&#8221; side of the work, there are three major categories of skills, those being &#8230;<\/p>\n<ul>\n<li>HTML (design)<\/li>\n<li>CSS (style)<\/li>\n<li>Javascript (workings)<\/li>\n<\/ul>\n<p> &#8230; and a subcategory of &#8220;Javascript (workings)&#8221; skills would definitely be &#8230;<\/p>\n<ul>\n<li>the use of arrays &#8230; and &#8230;<\/li>\n<li>array &#8220;methods&#8221;<\/li>\n<\/ul>\n<p> &#8230; &#8220;methods&#8221; being an object oriented idea of &#8220;actions applied to objects&#8221; (that is that slightly bit of a different result to &#8220;functions&#8221; overseeing and changing web application &#8220;workings&#8221; ignoring &#8220;objects&#8221; as such).  Maybe think of &#8220;methods&#8221; as an &#8220;adjectival way&#8221; to change a &#8220;noun&#8221; whereas &#8220;functions&#8221; are like &#8220;verbs&#8221; acting on the &#8220;webpage content&#8221;.<\/p>\n<p>In this context, we stumbled upon a great link called <a target=_blank title='Useful link, thanks' href='\/\/www.positronx.io\/javascript-array-push-pop-shift-unshift-methods\/'>JavaScript Array Push, Pop, Shift and Unshift Methods with Examples<\/a> that inspired me to construct a proof of concept web application to help a user who likes &#8220;hands on&#8221; approaches to learning, learn about array (object) &#8220;methods&#8221; &#8230;<\/p>\n<ul>\n<li><a target=_blank title='Javascript array push method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_push.asp'>push<\/a><\/li>\n<li><a target=_blank title='Javascript array pop method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_pop.asp'>pop<\/a><\/li>\n<li><a target=_blank title='Javascript array shift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_shift.asp'>shift<\/a><\/li>\n<li><a target=_blank title='Javascript array unshift method information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/jsref_unshift.asp'>unshift<\/a><\/li>\n<\/ul>\n<p> &#8230; in our inhouse HTML\/CSS\/Javascipt client side <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html_GETME\">array_work.html<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html\">live run<\/a> link you can try, also, below &#8230;<\/p>\n<p><iframe style=\"width:100%;height:800px;\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/array_work.html\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50399' onclick='var dv=document.getElementById(\"d50399\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/array\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50399' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50402' onclick='var dv=document.getElementById(\"d50402\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/game\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50402' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50407' onclick='var dv=document.getElementById(\"d50407\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/queue\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50407' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The arrays involved in yesterday&#8217;s Javascript Array Method Solar System Planets Game Tutorial can represent &#8220;order&#8221; where once there was none. And in inventory control, how you organize inventory pricing can use arrays in a &#8230; FIFO way &#8230; like &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-array-method-stack-and-queue-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[103,290,3428,476,1783,652,3427,1830,849,3425,3429,997,2135,2679,2587,2425,1319,3426,1418],"class_list":["post-50407","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-array","tag-data","tag-fifo","tag-game","tag-inventory","tag-javascript","tag-lifo","tag-method","tag-object","tag-pop","tag-pricing","tag-programming","tag-push","tag-queue","tag-shift","tag-stack","tag-tutorial","tag-unshift","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50407"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=50407"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50407\/revisions"}],"predecessor-version":[{"id":50412,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50407\/revisions\/50412"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=50407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=50407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=50407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}