{"id":106,"date":"2026-05-02T07:27:53","date_gmt":"2026-05-02T07:27:53","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=106"},"modified":"2026-05-02T07:27:57","modified_gmt":"2026-05-02T07:27:57","slug":"creating-arrays","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays","title":{"rendered":"Creating Arrays"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Arrays are used to store multiple values in a single variable. They are one of the most important data structures in JavaScript and are widely used for managing lists of data such as names, numbers, or objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is an Array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An array is a special variable that can hold more than one value at a time. Each value in an array is called an element, and each element has an index number starting from zero.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Use Arrays<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Arrays help organize data efficiently<br>They allow you to store multiple values in one place<br>They make it easier to loop through data<br>They simplify data management in applications<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Create an Array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can create an array using square brackets<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let fruits = &#91;\"Apple\", \"Banana\", \"Mango\"];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also create an empty array and add values later<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let colors = &#91;];<br>colors.push(\"Red\");<br>colors.push(\"Blue\");<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Array Elements<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each element in an array has an index starting from zero<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let fruits = &#91;\"Apple\", \"Banana\", \"Mango\"];<br>console.log(fruits&#91;0]);<br>console.log(fruits&#91;1]);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Modifying Array Elements<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can change values using their index<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits&#91;1] = \"Orange\";<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Elements to an Array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use push to add elements at the end<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits.push(\"Grapes\");<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use unshift to add elements at the beginning<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits.unshift(\"Pineapple\");<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Removing Elements from an Array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use pop to remove the last element<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits.pop();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use shift to remove the first element<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits.shift();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Array Length<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can check how many elements are in an array<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>console.log(fruits.length);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Looping Through an Array<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can use a loop to go through all elements<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (let i = 0; i &lt; fruits.length; i++) {<br>  console.log(fruits&#91;i]);<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Creating arrays in JavaScript is simple and essential for handling multiple values. Arrays make your code more organized and efficient, especially when working with lists of data in real world applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate JavaScript > Arrays > Creating Arrays<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777706729135\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777706728922\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-106","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating Arrays - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn how to create arrays in JavaScript with simple examples. Store manage and access multiple values easily in your code\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating Arrays - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn how to create arrays in JavaScript with simple examples. Store manage and access multiple values easily in your code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-02T07:27:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=creating-arrays\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=creating-arrays\",\"name\":\"Creating Arrays - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-02T07:27:53+00:00\",\"dateModified\":\"2026-05-02T07:27:57+00:00\",\"description\":\"Learn how to create arrays in JavaScript with simple examples. Store manage and access multiple values easily in your code\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=creating-arrays#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=creating-arrays\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=creating-arrays#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate JavaScript > Arrays > Creating Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating Arrays - Learn JavaScript with GIGZ.PK","description":"Learn how to create arrays in JavaScript with simple examples. Store manage and access multiple values easily in your code","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:\/\/gigz.pk\/javascript\/?lesson=creating-arrays","og_locale":"en_US","og_type":"article","og_title":"Creating Arrays - Learn JavaScript with GIGZ.PK","og_description":"Learn how to create arrays in JavaScript with simple examples. Store manage and access multiple values easily in your code","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-02T07:27:57+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays","url":"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays","name":"Creating Arrays - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-02T07:27:53+00:00","dateModified":"2026-05-02T07:27:57+00:00","description":"Learn how to create arrays in JavaScript with simple examples. Store manage and access multiple values easily in your code","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=creating-arrays#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Intermediate JavaScript > Arrays > Creating Arrays"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}