{"id":32879,"date":"2024-11-01T09:12:10","date_gmt":"2024-11-01T09:12:10","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32879"},"modified":"2024-11-01T11:21:38","modified_gmt":"2024-11-01T11:21:38","slug":"react-course-arrays","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32879\/","title":{"rendered":"React Course: Arrays"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! In this React tutorial, we will take an in-depth look at arrays. In JavaScript, arrays play a crucial role in storing and manipulating data, and in React, arrays are essential components for building the UI.<\/p>\n<h2>1. Basic Understanding of JavaScript Arrays<\/h2>\n<p>An array is a data structure that stores values sequentially. In JavaScript, arrays are a type of object that can hold various data types (strings, numbers, objects, etc.).<\/p>\n<pre><code>const fruits = [\"apple\", \"banana\", \"cherry\"];<\/code><\/pre>\n<p>The code above creates an array consisting of strings.<\/p>\n<h3>1.1 Key Properties and Methods of Arrays<\/h3>\n<ul>\n<li><strong>length<\/strong>: Returns the length of the array.<\/li>\n<li><strong>push()<\/strong>: Adds a new element to the end of the array.<\/li>\n<li><strong>pop()<\/strong>: Removes the last element from the array and returns that element.<\/li>\n<li><strong>shift()<\/strong>: Removes the first element from the array and returns that element.<\/li>\n<li><strong>unshift()<\/strong>: Adds a new element to the front of the array.<\/li>\n<li><strong>map()<\/strong>: Calls a given function on every element of the array and returns a new array.<\/li>\n<li><strong>filter()<\/strong>: Extracts only the elements that meet certain criteria and returns a new array.<\/li>\n<li><strong>reduce()<\/strong>: Executes a given function on each element of the array and returns a single value.<\/li>\n<\/ul>\n<h2>2. Using Arrays in React<\/h2>\n<p>In React, arrays are primarily used for managing component state and rendering lists. Creating UI components based on arrays is a very common task.<\/p>\n<h3>2.1 Rendering Components with Arrays<\/h3>\n<p>In React, you can dynamically render the UI by iterating over an array using a loop. The most common way is to use the <strong>map()<\/strong> method to convert each element of the array into JSX.<\/p>\n<pre><code>function FruitList({ fruits }) {\n        return (\n            &lt;ul&gt;\n                {fruits.map(fruit =&gt; &lt;li key={fruit}&gt;{fruit}&lt;\/li&gt;)}\n            &lt;\/ul&gt;\n        );\n    }<\/code><\/pre>\n<p>The code above shows a component that takes the <code>fruits<\/code> array and renders each fruit as a list item. Each element is given a <code>key<\/code> property so that React can uniquely identify each element of the array.<\/p>\n<h3>2.2 Managing Arrays with State<\/h3>\n<p>When managing state in React, you can use arrays. You can define an array as a state using the <strong>useState<\/strong> hook.<\/p>\n<pre><code>import React, { useState } from 'react';\n\n    function App() {\n        const [fruits, setFruits] = useState([\"apple\", \"banana\", \"cherry\"]);\n\n        const addFruit = (fruit) =&gt; {\n            setFruits([...fruits, fruit]);\n        };\n\n        return (\n            &lt;div&gt;\n                &lt;FruitList fruits={fruits} \/&gt;\n                &lt;button onClick={() =&gt; addFruit(\"mango\")}&gt;Add&lt;\/button&gt;\n            &lt;\/div&gt;\n        );\n    }<\/code><\/pre>\n<p>In the example above, the initial fruit array is set as state, and the logic to add a new fruit on button click is implemented.<\/p>\n<h2>3. Maintaining Array Immutability<\/h2>\n<p>When changing state in React, it is important that you do not directly modify the data but instead create a new data structure. Maintaining array immutability during this process is crucial.<\/p>\n<p>When updating an array, it is a good practice to use the <code>spread operator<\/code> (&#8230;) to create a new array and update the state.<\/p>\n<pre><code>const removeFruit = (fruit) =&gt; {\n        setFruits(fruits.filter(item =&gt; item !== fruit));\n    };<\/code><\/pre>\n<h2>4. Various Uses of Arrays: Enhancing User Experience<\/h2>\n<p>Using arrays in React provides many ways to enhance the user experience.<\/p>\n<h3>4.1 List Components<\/h3>\n<p>When creating list components, it is important to provide a unique key for each item. By using a unique key, React can efficiently manage changes to the list and optimize performance.<\/p>\n<h3>4.2 Implementing Search Functionality<\/h3>\n<p>You can implement search functionality that filters array data to show only the data that meets specific criteria. The <code>filter()<\/code> method can be used for this purpose.<\/p>\n<pre><code>const filteredFruits = fruits.filter(fruit =&gt; fruit.includes(searchTerm));<\/code><\/pre>\n<h3>4.3 Sorting Arrays<\/h3>\n<p>You can use the <code>sort()<\/code> method to sort data in an array. For example, if you want to sort fruit names alphabetically, you can do it like this:<\/p>\n<pre><code>const sortedFruits = [...fruits].sort();<\/code><\/pre>\n<h2>5. Conclusion<\/h2>\n<p>Arrays are a very important data structure in React. If you know the correct techniques and methods for handling arrays, you can provide a better interface for users. Based on what we covered in this tutorial, try out various ways to utilize arrays. With continuous practice and learning, I hope you enhance your skills as a React developer.<\/p>\n<p>In the next session, I will prepare material on <strong>React Hooks<\/strong>, so please look forward to it.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this React tutorial, we will take an in-depth look at arrays. In JavaScript, arrays play a crucial role in storing and manipulating data, and in React, arrays are essential components for building the UI. 1. Basic Understanding of JavaScript Arrays An array is a data structure that stores values sequentially. In JavaScript, arrays &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32879\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;React Course: Arrays&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[123],"tags":[],"class_list":["post-32879","post","type-post","status-publish","format-standard","hentry","category-react-basics-course"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>React Course: Arrays - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32879\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Course: Arrays - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this React tutorial, we will take an in-depth look at arrays. In JavaScript, arrays play a crucial role in storing and manipulating data, and in React, arrays are essential components for building the UI. 1. Basic Understanding of JavaScript Arrays An array is a data structure that stores values sequentially. In JavaScript, arrays &hellip; \ub354 \ubcf4\uae30 &quot;React Course: Arrays&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32879\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:12:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:21:38+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32879\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32879\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"React Course: Arrays\",\"datePublished\":\"2024-11-01T09:12:10+00:00\",\"dateModified\":\"2024-11-01T11:21:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32879\/\"},\"wordCount\":579,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"React basics course\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32879\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32879\/\",\"name\":\"React Course: Arrays - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:12:10+00:00\",\"dateModified\":\"2024-11-01T11:21:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32879\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32879\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32879\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Course: Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"React Course: Arrays - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/32879\/","og_locale":"ko_KR","og_type":"article","og_title":"React Course: Arrays - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this React tutorial, we will take an in-depth look at arrays. In JavaScript, arrays play a crucial role in storing and manipulating data, and in React, arrays are essential components for building the UI. 1. Basic Understanding of JavaScript Arrays An array is a data structure that stores values sequentially. In JavaScript, arrays &hellip; \ub354 \ubcf4\uae30 \"React Course: Arrays\"","og_url":"https:\/\/atmokpo.com\/w\/32879\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:12:10+00:00","article_modified_time":"2024-11-01T11:21:38+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32879\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32879\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"React Course: Arrays","datePublished":"2024-11-01T09:12:10+00:00","dateModified":"2024-11-01T11:21:38+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32879\/"},"wordCount":579,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["React basics course"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32879\/","url":"https:\/\/atmokpo.com\/w\/32879\/","name":"React Course: Arrays - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:12:10+00:00","dateModified":"2024-11-01T11:21:38+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32879\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32879\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32879\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"React Course: Arrays"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32879"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32879\/revisions"}],"predecessor-version":[{"id":32880,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32879\/revisions\/32880"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}