{"id":265,"date":"2009-04-25T07:26:01","date_gmt":"2009-04-25T14:26:01","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1227"},"modified":"2009-04-25T07:26:01","modified_gmt":"2009-04-25T14:26:01","slug":"2d-array-to-string","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=265","title":{"rendered":"2D Array to String"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nfunction format2D(a:Array):String {\r\n\tvar str:String=&quot;&#x5B;&quot;;\r\n\tfor (var i:int = 0; i&lt;a.length; i++) {\r\n\t\tstr+=&quot;&#x5B;&quot;+a&#x5B;i].toString()+&quot;],&quot;;\r\n\t}\r\n\tstr=str.substr(0,str.length-1);\r\n\tstr+=&quot;]&quot;;\r\n\treturn str;\r\n}\r\n\r\n\/\/ test it out\r\nvar array2D:Array = &#x5B;&#x5B;1,2,3], &#x5B;4,5,6], &#x5B;7,8,9]];\r\n\r\ntrace(array2D);\r\ntrace(format2D(array2D));\r\n\r\n\/* outputs:\r\n1,2,3,4,5,6,7,8,9\r\n&#x5B;&#x5B;1,2,3],&#x5B;4,5,6],&#x5B;7,8,9]]\r\n\r\n*\/\r\n<\/pre>\n<p>When you trace a 2D array to the output window the actual structure of the array isn&#8217;t clear. For some reason it just appears as a 1D array &#8211; this small function fixes that problem &#8211; it could also be used to save 2D arrays to text files etc&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>function format2D(a:Array):String { var str:String=&quot;&#x5B;&quot;; for (var i:int = 0; i&lt;a.length; i++) { str+=&quot;&#x5B;&quot;+a&#x5B;i].toString()+&quot;],&quot;; } str=str.substr(0,str.length-1); str+=&quot;]&quot;; return str; } \/\/ test it out var array2D:Array = &#x5B;&#x5B;1,2,3], &#x5B;4,5,6], &#x5B;7,8,9]]; trace(array2D); trace(format2D(array2D)); \/* outputs: 1,2,3,4,5,6,7,8,9 &#x5B;&#x5B;1,2,3],&#x5B;4,5,6],&#x5B;7,8,9]] *\/ When you trace a 2D array to the output window the actual structure of the array isn&#8217;t clear. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,21],"tags":[3,4],"class_list":["post-265","post","type-post","status-publish","format-standard","hentry","category-string-manipulation","category-strings","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/265\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}