{"id":15367,"date":"2023-07-26T09:00:00","date_gmt":"2023-07-26T00:00:00","guid":{"rendered":"https:\/\/www.autooffice.co.kr\/blog\/2023\/07\/26\/apps-script-myarray-function\/"},"modified":"2025-09-15T18:19:38","modified_gmt":"2025-09-15T09:19:38","slug":"apps-script-myarray-function","status":"publish","type":"post","link":"https:\/\/www.autooffice.co.kr\/en\/blog\/2023\/07\/26\/apps-script-myarray-function\/","title":{"rendered":"Array Basic"},"content":{"rendered":"<p>This post is a corrected post after AI explains the code included in the book <a title=\"\" href=\"https:\/\/www.autooffice.io\/content\/ebizbooks-apps-script\" target=\"_blank\" rel=\"noopener\">&#8220;Google Apps Script 101: Building Work Automation For Free&#8221;<\/a>. Added a <s>strikethrough<\/s> when editing what AI has written, and added <span style=\"color: #ff3366;\">color<\/span> when edited by author<\/p>\n<h2>Table of Contents<\/h2>\n<ol>\n<li><a href=\"#summary\">Summary<\/a><\/li>\n<li><a href=\"#code\">Code<\/a><\/li>\n<li><a href=\"#explanation\">Code Explanation<\/a><\/li>\n<li><a href=\"#example\">Example<\/a><\/li>\n<li><a href=\"#ai-prompt\">AI Prompt<\/a><\/li>\n<\/ol>\n<h2 id=\"summary\">Summary<\/h2>\n<p>In this blog post, we will explore the <code>myArray<\/code> function in Apps Script. This function logs the first element of an array to the Logger.<\/p>\n<h2 id=\"code\">Code<\/h2>\n<pre><code>function myArray() {\n  const array = ['a', 'b', 'c']\n  Logger.log(array[0])\n}<\/code><\/pre>\n<h2 id=\"explanation\">Code Explanation<\/h2>\n<p>The code defines a function called <code>myArray<\/code>. Inside the function, an array is created with three elements: &#8216;a&#8217;, &#8216;b&#8217;, and &#8216;c&#8217;. The <code>Logger.log<\/code> statement logs the first element of the array, which is &#8216;a&#8217;, to the Logger.<\/p>\n<h2 id=\"example\">Example<\/h2>\n<p>To execute the <code>myArray<\/code> function, simply call it in your Apps Script project. The first element of the array will be logged to the Logger.<\/p>\n<h2 id=\"ai-prompt\">AI Prompt<\/h2>\n<p>Write a function called <code>myArray<\/code> that logs the first element of the array [&#8216;a&#8217;, &#8216;b&#8217;, &#8216;c&#8217;] to the Logger.<\/p>\n<hr>\n<p><span style=\"color: #ff3366;\">This is a sample code that explains what an array is, but since no separate context was passed to the AI, it simply describes the function. If you ask the AI to explain what an array is in Apps Script, it will explain in detail: <\/span><\/p>\n<p>In Google Apps Script, an array is a data structure that allows you to store multiple values in a single variable. It is a collection of elements of the same data type, arranged in sequential order, and each value can be accessed using an index. For example, you can declare and initialize an array as follows:<\/p>\n<pre><code>\nvar fruits = [\"apple\", \"banana\", \"orange\", \"grape\"];\n<\/code><\/pre>\n<p>This array consists of four fruits: &#8220;apple,&#8221; &#8220;banana,&#8221; &#8220;orange,&#8221; and &#8220;grape.&#8221; Each fruit can be accessed using its index in the array. The index starts at 0 and goes up to one less than the length of the array. To access each element of the `fruits` array, you can do the following:<\/p>\n<pre><code>\nvar firstFruit = fruits[0]; \/\/ Access \"apple\"\nvar secondFruit = fruits[1]; \/\/ Access \"banana\"\nvar thirdFruit = fruits[2]; \/\/ Access \"orange\"\nvar fourthFruit = fruits[3]; \/\/ Access \"grape\"\n<\/code><\/pre>\n<p>Arrays are valuable data structures that allow you to store and manipulate a significant amount of data within a single variable. They are commonly used with loops to iterate through all elements or to perform various operations on the elements. Furthermore, arrays can be dynamically resized, and you can add or remove elements as needed. Arrays are widely used and versatile data structures in programming languages, including Google Apps Script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog post, we will explore the myArray function in Apps Script. This function logs the first element of an array to the Logger.<\/p>\n","protected":false},"author":1,"featured_media":15370,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[5,118],"tags":[512,69,522,7],"class_list":["post-15367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spreadsheet","category-apps-script","tag-ai-assisted","tag-script","tag-array","tag-spreadsheet"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"en","enabled_languages":["ko","en"],"languages":{"ko":{"title":true,"content":true,"excerpt":true},"en":{"title":true,"content":true,"excerpt":true}}},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/comments?post=15367"}],"version-history":[{"count":5,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15367\/revisions"}],"predecessor-version":[{"id":17211,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/posts\/15367\/revisions\/17211"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/media\/15370"}],"wp:attachment":[{"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/media?parent=15367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/categories?post=15367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.autooffice.co.kr\/en\/wp-json\/wp\/v2\/tags?post=15367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}