What are Arrays in JavaScript?
Published: 2022-10-28 18:04:24

<!-- wp:gallery {"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":16,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://michaelzibhome.files.wordpress.com/2022/10/0_w8ajmus7ziboip9k.jpg?w=880" alt="" class="wp-image-16"/></figure>



<!-- wp:heading {"level":1} -->
<h1>what is an array ?</h1>


<!-- wp:paragraph -->
<p>Array data structure is widely used in all programming languages that support it.but in this article we'll be looking at how to use it in  JavaScript.</p>


<!-- wp:paragraph -->
<p>In programming, an array is a collection of elements or items. Arrays store data as elements and retrieve them back when you need them.</p>


<!-- wp:paragraph -->
<p>In this article and the next one, I'll teach you all about arrays in JavaScript. You'll learn about complex data handling, destructuring, the most commonly used array methods, and more.</p>



<h2>Why this article on Array?</h2>


<!-- wp:paragraph -->
<p>You'll agree with me that there are many great articles on JavaScript arrays already available around the internet. so why did I waste my time writing this One? </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Well , for some time now I realize that  most beginners need a tutorial that covers arrays thoroughly from beginning to end with visual examples. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So that was what encouraged me to write this article , if you're just getting started with JavaScript, I hope this will be helpful to you.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Also as an experience developer, I hope this will come handy to you . As I'm writing this article I'm also learning.so let's get right on it.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>What is Array in JavaScript ?</h3>


<!-- wp:paragraph -->
<p>When you go to your search engine (eg.google),you type Array and you click on the search icon, you'll find that there are a lot of definition on arrays. But I'll give a simple meaning.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In JavaScript, array is a single variable that is used to store different elements. It is often used when we want to store a list of elements and access them by a single variable.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Creating an array.</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can create array using an array literal,this is the easiest way to create a JavaScript Array. check the example below:</p>


 
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":14,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://michaelzibhome.files.wordpress.com/2022/10/image_editor_output_image335511067-1666890589283.jpg?w=547" alt="" class="wp-image-14"/></figure>
<figcaption class="blocks-gallery-caption wp-element-caption">It is a common practice to declare arrays with the const keyword. If you want to learn more on with arrays, I'll be writing an article on that.</figcaption></figure>


<!-- wp:heading -->
<h2>Why Use Arrays?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Let's say you have a list of names of cars , like the one in the image below,and you want to loop through the cars and find a specific one? you can use array . What If  you have 300 and not 3? You can use array.</p>
<!-- /wp:paragraph -->

<!-- wp:gallery {"linkTo":"none"} -->
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":13,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://michaelzibhome.files.wordpress.com/2022/10/screenshot_20221027-180644.jpg?w=625" alt="" class="wp-image-13"/></figure>



<!-- wp:heading -->
<h2>Conclusion.</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Thanks for reading this introductory article on Array in JavaScript,I hope you found it helpful. In my next article I'll be explaining How to Get Elements from an Array in JS,How to Add Elements to an Array in JS and more.. so tune in,and till next time take care 😘.</p>
<!-- /wp:paragraph -->