{"id":49,"date":"2019-03-15T23:19:06","date_gmt":"2019-03-15T23:19:06","guid":{"rendered":"https:\/\/avantutor.com\/blog\/?p=49"},"modified":"2019-04-26T21:20:49","modified_gmt":"2019-04-26T21:20:49","slug":"arrays","status":"publish","type":"post","link":"https:\/\/avantutor.com\/blog\/arrays\/","title":{"rendered":"Arrays Explained"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"387\" src=\"https:\/\/avantutor.com\/blog\/wp-content\/uploads\/2019\/03\/cspr_0601.png\" alt=\"A simple visual depiction of an array with five elements of type integer.\" class=\"wp-image-52\" srcset=\"https:\/\/avantutor.com\/blog\/wp-content\/uploads\/2019\/03\/cspr_0601.png 1000w, https:\/\/avantutor.com\/blog\/wp-content\/uploads\/2019\/03\/cspr_0601-300x116.png 300w, https:\/\/avantutor.com\/blog\/wp-content\/uploads\/2019\/03\/cspr_0601-768x297.png 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What is an Array?<\/h2>\n\n\n\n<p>Arrays are a popular type of <strong>data structure<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Data Structure?<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>  In&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Computer_science\">computer science<\/a>, a&nbsp;<strong>data structure<\/strong>&nbsp;is a data organization, management and storage format that enables&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Algorithmic_efficiency\">efficient<\/a>&nbsp;access and modification.<sup><a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_structure#cite_note-1\">[1]<\/a><a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_structure#cite_note-2\">[2]<\/a><a href=\"https:\/\/en.wikipedia.org\/wiki\/Data_structure#cite_note-3\">[3]<\/a><\/sup>&nbsp;More precisely, a data structure is a collection of&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Data\">data values<\/a>, the relationships among them, and the functions or operations that can be applied to the data.<\/p><cite>Wikipedia<\/cite><\/blockquote>\n\n\n\n<p>In the simplest terms: <strong>data structure stores data in an organized way!<\/strong>  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Arrays Store Data<\/h2>\n\n\n\n<p>In the <strong>array data structure<\/strong>, data values are stored at specific <strong>locations<\/strong>.  Each location is identified by a number (<strong>index<\/strong>).  Location or indices (plural of index) start at 0.  <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example: <\/h4>\n\n\n\n<ul><li>Location <strong>0<\/strong> stores the text <strong>&#8220;Jason&#8221;<\/strong><\/li><li>Location <strong>1<\/strong> stores the text <strong>&#8220;Roberta&#8221;<\/strong><\/li><li>Location <strong>2 <\/strong>stores the text <strong>&#8220;Jessie&#8221;<\/strong><\/li><\/ul>\n\n\n\n<p>&#8230;.<\/p>\n\n\n\n<p>Simple right? <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Naming Arrays<\/h2>\n\n\n\n<p>But how do we reference this array data structure?  In other words what do we call this specific array?  <\/p>\n\n\n\n<p>Let&#8217;s give it a name. Looking at the values it looks like we are storing names so call it &#8216;<strong>names<\/strong>&#8216;?  I think that makes sense. <\/p>\n\n\n\n<p><strong>names<\/strong> = [0 &#8211;&gt; <strong>&#8220;Jason&#8221;<\/strong> , 1 &#8211;&gt; &#8220;<strong>Roberta<\/strong>&#8220;, 2 &#8211;&gt; &#8220;<strong>Jessie&#8221;<\/strong>]<\/p>\n\n\n\n<p>So &#8216;<strong>names<\/strong>&#8216; refers to [Jason, Roberta and Jessie]. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it Looks in Code <\/h2>\n\n\n\n<p>Let&#8217;s pick <strong>javascript<\/strong> as the programming language for the programming examples.  This is how the &#8216;names&#8217; array looks in javascript.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var names = [\"Jason\", \"Roberta\", \"Jessie\"];<\/code><\/pre>\n\n\n\n<p>Still with me?  Pretty straight forward right? I bet you can tell me what is stored in &#8216;names&#8217; array at location 1.  If you said &#8220;Roberta&#8221; you are correct! If you said &#8220;Jason&#8221; you must have forgotten that locations start at 0 not 1 so location 0 is &#8220;Jason&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Values in an Array<\/h2>\n\n\n\n<p>What if you wanted to access the value at location 2?  This would be the same as the third item in the &#8216;names&#8217; array since location start at 0 not 1. 0 is the first value, 1 is the second value, 2 is the third value. <\/p>\n\n\n\n<p>We want the value of <strong>names at location 2<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>names[2];\ufeff<\/code><\/pre>\n\n\n\n<p><strong>names[2]<\/strong> returns the value &#8220;Jessie&#8221;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Changing Values in an Array<\/h2>\n\n\n\n<p>What if you wanted to change the value in an array? Simple.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>names[0] = \"Abdul\";<\/code><\/pre>\n\n\n\n<p>Now <strong>names<\/strong> looks like [Abdul, Roberta, Jessie]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding a Value to an Array<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>names[3] = \"Alita\";<\/code><\/pre>\n\n\n\n<p>Location 2 stored the last item in the array.  So we pick location 3 to store the new item.  Nothing was stored in location 3 so we should be good.  <\/p>\n\n\n\n<p><strong>names<\/strong> looks like [Abdul, Roberta, Jessie, Alita] now<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"mce_72\">Removing a Value in an Array<\/h2>\n\n\n\n<p>Don&#8217;t ask. It&#8217;s not as straightforward as adding or modifying.  All you need to know that there are built in function that can be used to accomplish the task.  If you just can&#8217;t let go try googling &#8216;<strong>javascript splice function to remove element<\/strong>&#8216;.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">More on Arrays<\/h2>\n\n\n\n<p>Arrays are a <strong>popular<\/strong> data structure.  They are <strong>simple and efficient<\/strong>.  We used text or <strong>string<\/strong> for the value <strong>type<\/strong>.  You can use <strong>other types<\/strong> such as <strong>numbers<\/strong> or <strong>ints<\/strong>.  And if you use arrays in <strong>javascript<\/strong> you can <strong>mix the types<\/strong>.  Also, in most programming languages arrays have <strong>built-in functions <\/strong>that return various things such as the <strong>length<\/strong> of an array or <strong>the last item<\/strong> in an array.   <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Arrays are a popular data structure.  They are efficient and well organized.  They make working with a data set a breeze.  They become even more appealing once you understand and work with its built-in functionalities.  <\/p>\n\n\n\n<p>Feel free to comment your concerns below or reach out to me if you are interested in learning more about arrays or any other data structure for that matter! <\/p>\n\n\n\n<p>Happy Coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is an Array? Arrays are a popular type of data structure. What is a Data Structure? In&nbsp;computer science, a&nbsp;data structure&nbsp;is a data organization, management and storage format that enables&nbsp;efficient&nbsp;access and modification.[1][2][3]&nbsp;More precisely, a data structure is a collection of&nbsp;data&#8230; <a class=\"more-link\" href=\"https:\/\/avantutor.com\/blog\/arrays\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[8,21],"tags":[9,12,11],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Arrays Explained - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding<\/title>\n<meta name=\"description\" content=\"Learn about arrays in simple and straightforward terms. Find out what arrays are and how to work with them. No programming knowledge necessary!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/avantutor.com\/blog\/arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arrays Explained - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"og:description\" content=\"Learn about arrays in simple and straightforward terms. Find out what arrays are and how to work with them. No programming knowledge necessary!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/avantutor.com\/blog\/arrays\/\" \/>\n<meta property=\"og:site_name\" content=\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-15T23:19:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-26T21:20:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/avantutor.com\/blog\/wp-content\/uploads\/2019\/03\/cspr_0601.png\" \/>\n<meta name=\"author\" content=\"avansardar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"avansardar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/avantutor.com\/blog\/arrays\/\",\"url\":\"https:\/\/avantutor.com\/blog\/arrays\/\",\"name\":\"Arrays Explained - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"isPartOf\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#website\"},\"datePublished\":\"2019-03-15T23:19:06+00:00\",\"dateModified\":\"2019-04-26T21:20:49+00:00\",\"author\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\"},\"description\":\"Learn about arrays in simple and straightforward terms. Find out what arrays are and how to work with them. No programming knowledge necessary!\",\"breadcrumb\":{\"@id\":\"https:\/\/avantutor.com\/blog\/arrays\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/avantutor.com\/blog\/arrays\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/avantutor.com\/blog\/arrays\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/avantutor.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arrays Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/avantutor.com\/blog\/#website\",\"url\":\"https:\/\/avantutor.com\/blog\/\",\"name\":\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"description\":\"Looking for expert advice on how to improve your coding skills? The AvanTutor blog provides a wealth of resources and insights to help you become a better programmer. Our experienced tutors share tips and tricks for mastering popular programming languages such as Java, and JavaScript, as well as insights into the latest trends in software development. With regular updates and engaging content, the AvanTutor blog is your go-to resource for all things coding.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/avantutor.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\",\"name\":\"avansardar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g\",\"caption\":\"avansardar\"},\"url\":\"https:\/\/avantutor.com\/blog\/author\/avansardar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Arrays Explained - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Learn about arrays in simple and straightforward terms. Find out what arrays are and how to work with them. No programming knowledge necessary!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/avantutor.com\/blog\/arrays\/","og_locale":"en_US","og_type":"article","og_title":"Arrays Explained - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","og_description":"Learn about arrays in simple and straightforward terms. Find out what arrays are and how to work with them. No programming knowledge necessary!","og_url":"https:\/\/avantutor.com\/blog\/arrays\/","og_site_name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","article_published_time":"2019-03-15T23:19:06+00:00","article_modified_time":"2019-04-26T21:20:49+00:00","og_image":[{"url":"https:\/\/avantutor.com\/blog\/wp-content\/uploads\/2019\/03\/cspr_0601.png"}],"author":"avansardar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"avansardar","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/avantutor.com\/blog\/arrays\/","url":"https:\/\/avantutor.com\/blog\/arrays\/","name":"Arrays Explained - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","isPartOf":{"@id":"https:\/\/avantutor.com\/blog\/#website"},"datePublished":"2019-03-15T23:19:06+00:00","dateModified":"2019-04-26T21:20:49+00:00","author":{"@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e"},"description":"Learn about arrays in simple and straightforward terms. Find out what arrays are and how to work with them. No programming knowledge necessary!","breadcrumb":{"@id":"https:\/\/avantutor.com\/blog\/arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/avantutor.com\/blog\/arrays\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/avantutor.com\/blog\/arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/avantutor.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Arrays Explained"}]},{"@type":"WebSite","@id":"https:\/\/avantutor.com\/blog\/#website","url":"https:\/\/avantutor.com\/blog\/","name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Looking for expert advice on how to improve your coding skills? The AvanTutor blog provides a wealth of resources and insights to help you become a better programmer. Our experienced tutors share tips and tricks for mastering popular programming languages such as Java, and JavaScript, as well as insights into the latest trends in software development. With regular updates and engaging content, the AvanTutor blog is your go-to resource for all things coding.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/avantutor.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e","name":"avansardar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g","caption":"avansardar"},"url":"https:\/\/avantutor.com\/blog\/author\/avansardar\/"}]}},"_links":{"self":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/49"}],"collection":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":16,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":209,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/49\/revisions\/209"}],"wp:attachment":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}