{"id":211,"date":"2009-07-27T22:23:37","date_gmt":"2009-07-27T21:23:37","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=211"},"modified":"2009-07-27T22:24:55","modified_gmt":"2009-07-27T21:24:55","slug":"arrays-insert-into-a-div","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/arrays-insert-into-a-div\/","title":{"rendered":"Arrays &#8211; Insert into a div"},"content":{"rendered":"<p>Javascript arrays are just like any other object orientated language, in the aspect an array is a block of memory associated with main object.  To create an array in Javascript just need to call<br \/>\n<object> = Array(5);<br \/>\nOr<br \/>\n<object> = Array(&#8216;value1&#8242;,&#8217;value2&#8217;);<\/p>\n<p>The code below is using a default screen from which you press the &#8216;Click Here&#8217; button and the array is used to insert into a &lt;div&gt; html tag.  To insert into a div tag within javascript, there needs to be a new node created and in this instance a text node is created which in turn is appended to the div.<\/p>\n<p>The code hopefully will explain more.<\/p>\n<pre lang=\"javascript\">\r\n<html>\r\n       <script language=\"javascript\">\r\n              \/\/ setup the main array\r\n              var setArray = Array(\"hi\", \"there\", \"this\", \"is\", \"a\",\"test\");\r\n\r\n              \/\/ insert the array into the DIV smalltest object\r\n              function insertArray()\r\n              {\r\n                     var theText = \"\";  \/\/ set the theText output to an empty string otherwise it would start with null.\r\n                     for (var i=0; i < setArray.length; i++)\r\n                     {\r\n                            \/\/ create the array of text to insert\r\n                            theText += setArray[i];\r\n                     }\r\n                     \/\/ create the createTextNode \r\n                     var insertText = document.createTextNode(theText);\r\n                     document.getElementById(\"smalltest\").appendChild(insertText);\r\n              }\r\n       <\/script>\r\n       <body>\r\n              Just a small test, \r\n              <div id=\"smalltest\">\r\n              <\/div>\r\n              <input type=\"submit\" value=\"click here\" onclick=\"javascript:insertArray()\" \/>\r\n       <\/body>\r\n<\/html>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Javascript arrays are just like any other object orientated language, in the aspect an array is a block of memory associated with main object. To create an array in Javascript just need to call = Array(5); Or = Array(&#8216;value1&#8242;,&#8217;value2&#8217;); The code below is using a default screen from which you press the &#8216;Click Here&#8217; button &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/arrays-insert-into-a-div\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arrays &#8211; Insert into a div<\/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":[16],"tags":[402,398,400],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-javascript","tag-linux","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=211"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/211\/revisions\/213"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}