{"id":103,"date":"2024-11-08T04:47:02","date_gmt":"2024-11-08T04:47:02","guid":{"rendered":"https:\/\/techkubo.com\/javascript\/?p=103"},"modified":"2025-05-13T11:57:59","modified_gmt":"2025-05-13T11:57:59","slug":"javascript-arrays","status":"publish","type":"post","link":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/","title":{"rendered":"JavaScript Arrays"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>What is an Array?<\/strong><\/h2>\n\n\n\n<p>An array is a special variable that can hold multiple values at once. Arrays are useful for storing lists of data, such as numbers, strings, or objects.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating Arrays <\/strong><\/h2>\n\n\n\n<p>You can create arrays using the array literal syntax or the <code>Array<\/code> constructor.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Array Literal Syntax<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Array Constructor<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = new Array(&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;);\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Accessing Array Elements<\/strong><\/h2>\n\n\n\n<p>You can access array elements using their index. Array indices start at 0.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nconsole.log(fruits[0]);  \/\/ Output: Apple\nconsole.log(fruits[1]);  \/\/ Output: Banana\nconsole.log(fruits[2]);  \/\/ Output: Cherry<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Modifying Array Elements<\/strong><\/h2>\n\n\n\n<p>You can modify elements in an array by accessing them using their index.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nfruits[1] = &quot;Blueberry&quot;;\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Blueberry&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Array Properties<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Length<\/strong><\/h3>\n\n\n\n<p>The <code>length<\/code> property returns the number of elements in an array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nconsole.log(fruits.length);  \/\/ Output: 3<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Array Methods<\/strong><\/h2>\n\n\n\n<p>JavaScript provides various methods to manipulate arrays.<\/p>\n\n\n\n<p><strong>1. push()<\/strong><\/p>\n\n\n\n<p>The <code>push()<\/code> method adds one or more elements to the end of an array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;];\nfruits.push(&quot;Cherry&quot;);\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><strong>2. pop()<\/strong><\/p>\n\n\n\n<p>The <code>pop()<\/code> method removes the last element from an array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nfruits.pop();\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Banana&quot;]<\/pre><\/div>\n\n\n\n<p><strong>3. shift()<\/strong><\/p>\n\n\n\n<p>The <code>shift()<\/code> method removes the first element from an array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nfruits.shift();\nconsole.log(fruits);  \/\/ Output: [&quot;Banana&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><strong>4. unshift()<\/strong><\/p>\n\n\n\n<p>The <code>unshift()<\/code> method adds one or more elements to the beginning of an array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Banana&quot;, &quot;Cherry&quot;];\nfruits.unshift(&quot;Apple&quot;);\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><strong>5. splice()<\/strong><\/p>\n\n\n\n<p>The <code>splice()<\/code> method adds or removes elements from an array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nfruits.splice(1, 1, &quot;Blueberry&quot;, &quot;Mango&quot;);\nconsole.log(fruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Blueberry&quot;, &quot;Mango&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><strong>6. slice()<\/strong><\/p>\n\n\n\n<p>The <code>slice()<\/code> method returns a new array containing a portion of an existing array.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nlet citrus = fruits.slice(1, 3);\nconsole.log(citrus);  \/\/ Output: [&quot;Banana&quot;, &quot;Cherry&quot;]<\/pre><\/div>\n\n\n\n<p><strong>7. concat()<\/strong><\/p>\n\n\n\n<p>The <code>concat()<\/code> method merges two or more arrays.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;];\nlet moreFruits = [&quot;Cherry&quot;, &quot;Date&quot;];\nlet allFruits = fruits.concat(moreFruits);\nconsole.log(allFruits);  \/\/ Output: [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;, &quot;Date&quot;]<\/pre><\/div>\n\n\n\n<p><strong>8. join()<\/strong><\/p>\n\n\n\n<p>The <code>join()<\/code> method joins all elements of an array into a string.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;JavaScript&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\nlet fruitString = fruits.join(&quot;, &quot;);\nconsole.log(fruitString);  \/\/ Output: &quot;Apple, Banana, Cherry&quot;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>JavaScript Arrays Example Code<\/strong><\/h2>\n\n\n\n<p><strong>Explanation of Code:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Creating Arrays<\/strong>: Demonstrates creating arrays using the array literal syntax.<\/li>\n\n\n\n<li><strong>Accessing Elements<\/strong>: Accesses elements using their index.<\/li>\n\n\n\n<li><strong>Modifying Elements<\/strong>: Modifies elements using their index.<\/li>\n\n\n\n<li><strong>Array Properties<\/strong>: Uses the <code>length<\/code> property to get the number of elements.<\/li>\n\n\n\n<li><strong>Array Methods<\/strong>: Demonstrates various array methods such as <code>push<\/code>, <code>pop<\/code>, <code>shift<\/code>, <code>unshift<\/code>, <code>splice<\/code>, <code>slice<\/code>, <code>concat<\/code>, and <code>join<\/code>.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;HTML&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;title&gt;JavaScript Arrays Example&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;script&gt;\n        let fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;];\n\n        \/\/ Accessing elements\n        console.log(&quot;First fruit: &quot; + fruits[0]);  \/\/ Output: First fruit: Apple\n\n        \/\/ Modifying elements\n        fruits[1] = &quot;Blueberry&quot;;\n        console.log(&quot;Modified fruits: &quot; + fruits);  \/\/ Output: Modified fruits: Apple,Blueberry,Cherry\n\n        \/\/ Array properties\n        console.log(&quot;Number of fruits: &quot; + fruits.length);  \/\/ Output: Number of fruits: 3\n\n        \/\/ Array methods\n        fruits.push(&quot;Mango&quot;);\n        console.log(&quot;After push: &quot; + fruits);  \/\/ Output: After push: Apple,Blueberry,Cherry,Mango\n\n        fruits.pop();\n        console.log(&quot;After pop: &quot; + fruits);  \/\/ Output: After pop: Apple,Blueberry,Cherry\n\n        fruits.shift();\n        console.log(&quot;After shift: &quot; + fruits);  \/\/ Output: After shift: Blueberry,Cherry\n\n        fruits.unshift(&quot;Apple&quot;);\n        console.log(&quot;After unshift: &quot; + fruits);  \/\/ Output: After unshift: Apple,Blueberry,Cherry\n\n        fruits.splice(1, 1, &quot;Pineapple&quot;, &quot;Grapes&quot;);\n        console.log(&quot;After splice: &quot; + fruits);  \/\/ Output: After splice: Apple,Pineapple,Grapes,Cherry\n\n        let citrus = fruits.slice(1, 3);\n        console.log(&quot;After slice: &quot; + citrus);  \/\/ Output: After slice: Pineapple,Grapes\n\n        let moreFruits = [&quot;Orange&quot;, &quot;Peach&quot;];\n        let allFruits = fruits.concat(moreFruits);\n        console.log(&quot;After concat: &quot; + allFruits);  \/\/ Output: After concat: Apple,Pineapple,Grapes,Cherry,Orange,Peach\n\n        let fruitString = fruits.join(&quot;, &quot;);\n        console.log(&quot;After join: &quot; + fruitString);  \/\/ Output: After join: Apple, Pineapple, Grapes, Cherry\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"460\" src=\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png\" alt=\"\" class=\"wp-image-105\" style=\"width:1200px;height:auto\" srcset=\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png 1024w, https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1-300x135.png 300w, https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1-768x345.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>JavaScript Labs<\/strong><\/h2>\n\n\n\n<iframe src=\"https:\/\/techkubo.com\/javascript-sim.html\" title=\"Try HTML on TechKubo\" width=\"100%\" height=\"500\"><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>What is an Array? An array is a special variable that can hold multiple values at once. Arrays are useful [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript Arrays - JavaScript Tutorial<\/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:\/\/techkubo.com\/javascript\/javascript-arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Arrays - JavaScript Tutorial\" \/>\n<meta property=\"og:description\" content=\"What is an Array? An array is a special variable that can hold multiple values at once. Arrays are useful [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/\" \/>\n<meta property=\"og:site_name\" content=\"JavaScript Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-08T04:47:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-13T11:57:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"460\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Manong\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/\"},\"author\":{\"name\":\"Manong\",\"@id\":\"https:\/\/techkubo.com\/javascript\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\"},\"headline\":\"JavaScript Arrays\",\"datePublished\":\"2024-11-08T04:47:02+00:00\",\"dateModified\":\"2025-05-13T11:57:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/\"},\"wordCount\":250,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/#organization\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png\",\"articleSection\":[\"javascript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/\",\"url\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/\",\"name\":\"JavaScript Arrays - JavaScript Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png\",\"datePublished\":\"2024-11-08T04:47:02+00:00\",\"dateModified\":\"2025-05-13T11:57:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage\",\"url\":\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png\",\"contentUrl\":\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png\",\"width\":1024,\"height\":460},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/techkubo.com\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/techkubo.com\/javascript\/#website\",\"url\":\"https:\/\/techkubo.com\/javascript\/\",\"name\":\"JavaScript Tutorial\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/techkubo.com\/javascript\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/techkubo.com\/javascript\/#organization\",\"name\":\"JavaScript Tutorial\",\"url\":\"https:\/\/techkubo.com\/javascript\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/javascript\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2025\/01\/cropped-Techkubo-logo-1.png\",\"contentUrl\":\"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2025\/01\/cropped-Techkubo-logo-1.png\",\"width\":1618,\"height\":1174,\"caption\":\"JavaScript Tutorial\"},\"image\":{\"@id\":\"https:\/\/techkubo.com\/javascript\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/techkubo.com\/javascript\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965\",\"name\":\"Manong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/techkubo.com\/javascript\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g\",\"caption\":\"Manong\"},\"sameAs\":[\"https:\/\/techkubo.com\"],\"url\":\"https:\/\/techkubo.com\/javascript\/author\/manong\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Arrays - JavaScript Tutorial","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:\/\/techkubo.com\/javascript\/javascript-arrays\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Arrays - JavaScript Tutorial","og_description":"What is an Array? An array is a special variable that can hold multiple values at once. Arrays are useful [&hellip;]","og_url":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/","og_site_name":"JavaScript Tutorial","article_published_time":"2024-11-08T04:47:02+00:00","article_modified_time":"2025-05-13T11:57:59+00:00","og_image":[{"width":1024,"height":460,"url":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png","type":"image\/png"}],"author":"Manong","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Manong","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#article","isPartOf":{"@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/"},"author":{"name":"Manong","@id":"https:\/\/techkubo.com\/javascript\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965"},"headline":"JavaScript Arrays","datePublished":"2024-11-08T04:47:02+00:00","dateModified":"2025-05-13T11:57:59+00:00","mainEntityOfPage":{"@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/"},"wordCount":250,"commentCount":0,"publisher":{"@id":"https:\/\/techkubo.com\/javascript\/#organization"},"image":{"@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png","articleSection":["javascript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techkubo.com\/javascript\/javascript-arrays\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/","url":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/","name":"JavaScript Arrays - JavaScript Tutorial","isPartOf":{"@id":"https:\/\/techkubo.com\/javascript\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage"},"image":{"@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png","datePublished":"2024-11-08T04:47:02+00:00","dateModified":"2025-05-13T11:57:59+00:00","breadcrumb":{"@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techkubo.com\/javascript\/javascript-arrays\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#primaryimage","url":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png","contentUrl":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2024\/11\/JS-Arrays-Image1.png","width":1024,"height":460},{"@type":"BreadcrumbList","@id":"https:\/\/techkubo.com\/javascript\/javascript-arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techkubo.com\/javascript\/"},{"@type":"ListItem","position":2,"name":"JavaScript Arrays"}]},{"@type":"WebSite","@id":"https:\/\/techkubo.com\/javascript\/#website","url":"https:\/\/techkubo.com\/javascript\/","name":"JavaScript Tutorial","description":"","publisher":{"@id":"https:\/\/techkubo.com\/javascript\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techkubo.com\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techkubo.com\/javascript\/#organization","name":"JavaScript Tutorial","url":"https:\/\/techkubo.com\/javascript\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/javascript\/#\/schema\/logo\/image\/","url":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2025\/01\/cropped-Techkubo-logo-1.png","contentUrl":"https:\/\/techkubo.com\/javascript\/wp-content\/uploads\/sites\/7\/2025\/01\/cropped-Techkubo-logo-1.png","width":1618,"height":1174,"caption":"JavaScript Tutorial"},"image":{"@id":"https:\/\/techkubo.com\/javascript\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/techkubo.com\/javascript\/#\/schema\/person\/b4fa2f01fa4ff2a4e98276ce47115965","name":"Manong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techkubo.com\/javascript\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21a7455736c21887b8fefe0935012d65?s=96&d=mm&r=g","caption":"Manong"},"sameAs":["https:\/\/techkubo.com"],"url":"https:\/\/techkubo.com\/javascript\/author\/manong\/"}]}},"_links":{"self":[{"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/posts\/103"}],"collection":[{"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":2,"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/posts\/103\/revisions\/213"}],"wp:attachment":[{"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techkubo.com\/javascript\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}