{"id":26778,"date":"2016-07-12T21:01:32","date_gmt":"2016-07-12T13:01:32","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=26778"},"modified":"2023-11-15T19:48:59","modified_gmt":"2023-11-15T11:48:59","slug":"javascript-arrays","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/","title":{"rendered":"JavaScript Arrays and the 3 Things You Should Know"},"content":{"rendered":"<p><strong>Arrays<\/strong> are common in programming; they are <strong>special types of variables<\/strong> that can hold many values at once. But JavaScript has some unique array features that aren\u2019t widely known.<\/p>\n<p>In this blog, we\u2019ll dive into three lesser-known but significant aspects of JavaScript arrays that may be new to you.<\/p>\n<h2>1. Adding Custom Features to Arrays<\/h2>\n<p>When you dive deep into JavaScript arrays, you\u2019ll realize that at their core, they\u2019re essentially <strong>objects<\/strong>.<\/p>\n<p>Most things in JavaScript are actually <strong>objects<\/strong>. There are primarily two data categories in JavaScript: <strong>primitives<\/strong> and <strong>objects<\/strong>. But even primitives eventually get wrapped inside objects.<\/p>\n<p>Entities like <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\">Array<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\">Function<\/a>, and <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Date\">Date<\/a> are all <strong>predefined JavaScript objects<\/strong>. They come with their methods, properties, and a standard structure.<\/p>\n<p>Specifically, JavaScript arrays can have three types of properties:<\/p>\n<ol>\n<li><strong>Indices<\/strong> which are part of any array<\/li>\n<li><strong>Default properties<\/strong> given by JavaScript<\/li>\n<li><strong>Custom properties<\/strong> that you can personally add<\/li>\n<\/ol>\n<p>While most are familiar with the first two, we\u2019ll quickly overview them before diving into how you can include your own custom property.<\/p>\n<h3>Understanding Indices as Properties<\/h3>\n<p>In JavaScript, arrays use the <strong>square bracket syntax<\/strong>, like <code>var fruitsArray = [\"orange\", \"apple\", \"lychee\"];<\/code>.<\/p>\n<p>Here, indices of array elements act as <strong>properties<\/strong>, and these property names are always positive integers. It\u2019s a lot like how objects have a key-value structure.<\/p>\n<p>You can think of the array index as the object\u2019s key. And just like you can set an object\u2019s key, you can also set an array\u2019s index. For example, <code>fruitsArray[3] = \"peach\";<\/code>.<\/p>\n<h3>Using Built-in Properties<\/h3>\n<p>Arrays come with some <strong>built-in properties<\/strong>, like <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\/length\">array.length<\/a><\/code>. This property, for instance, indicates an array\u2019s length.<\/p>\n<p>These default properties are commonly found in many of JavaScript\u2019s predefined objects. They, along with some built-in methods, are what make these objects versatile for various uses.<\/p>\n<p>You can access these properties either using the <code>object.property<\/code> or <code>object[\"property\"]<\/code> syntax. So, <code>fruitsArray[\"length\"]<\/code> will give you the length of the array.<\/p>\n<h3>How to Add Your Custom Properties<\/h3>\n<p>Now, onto the fun part: <strong>adding your own properties to arrays<\/strong>. Though arrays are designed to store values at different indices, you might sometimes want to add some custom properties.<\/p>\n<p>Usually, beginners aren\u2019t introduced to this feature because it\u2019s not frequently used. If you\u2019re looking to add key-value pairs to an array, you might as well use a regular object. However, there can be cases where adding a custom property to an array can be handy.<\/p>\n<p>For instance, you could add a custom property to identify the \u201ctype\u201d or \u201cgroup\u201d of its elements, as shown in the example below:<\/p>\n<pre>\r\n var fruitsArray = [\"orange\", \"apple\", \"lychee\"];\r\n fruitsArray.typeOfItems = \"fruits\";\r\n \r\n console.log(fruitsArray + \" are \" + fruitsArray.typeOfItems);\r\n \/\/ \"orange,apple,lychee are fruits\"\r\n<\/pre>\n<p>Remember, any custom property you add to an array will be <strong>enumerable<\/strong>. That means, it\u2019ll show up when using loops like the <code><a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Statements\/for...in\">for\u2026in<\/a><\/code> statement.<\/p>\n<h2>2. Iterating Through Array Elements<\/h2>\n<p>Many might say, \u201cI\u2019ve got this covered,\u201d when it comes to looping through arrays. While that\u2019s often true, it\u2019s important to note that when we talk about looping through arrays, we\u2019re essentially looping through their <strong>indices<\/strong>.<\/p>\n<p>Since array indices are exclusively <strong>non-negative integers<\/strong>, the typical method involves iterating from zero up to the array\u2019s length. During each iteration, the current index is used to access the corresponding array element.<\/p>\n<p>However, with the advent of <a href=\"https:\/\/www.hongkiat.com\/blog\/ecmascript-6\/\">ECMAScript 6 (ES6)<\/a>, we gained a more direct method to loop through array elements, bypassing the indices. This is achieved using the <code>for\u2026of<\/code> loop.<\/p>\n<div class=\"su-quote su-quote-style-default su_quote-v7 su-quote-has-cite\">\n<div class=\"su-quote-inner su-u-clearfix su-u-trim\">The for\u2026of statement creates a loop iterating over iterable objects (including Array, Map, Set, String, TypedArray, arguments object, and so on), invoking a custom iteration hook with statements to be executed for the value of each distinct property.<span class=\"su-quote-cite\"><a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Statements\/for...of\" target=\"_blank\">MDN<\/a><\/span><\/div>\n<\/div>\n<p>In the context of arrays, the <code>for...of<\/code> loop traverses through the array elements, respecting their index order. Essentially, it handles the index iteration and fetches the <strong>corresponding array value<\/strong> at each step. This loop is particularly useful when you need to process all the elements in an array.<\/p>\n<pre>\r\n var fruitsArray = [\"orange\", \"apple\", \"lychee\"];\r\n \r\n for (let fruit of fruitsArray){\r\n     console.log(fruit);\r\n }\r\n \/\/ Output: \"orange\", \"apple\", \"lychee\"\r\n<\/pre>\n<p>Contrast this with the classic <code><a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Statements\/for\">for<\/a><\/code> loop, where the iteration is over indices rather than values:<\/p>\n<pre>\r\n var fruitsArray = [\"orange\", \"apple\", \"lychee\"];\r\n \r\n for (var index = 0; index &lt; fruitsArray.length; index++){\r\n     console.log(index);\r\n }\r\n \/\/ Output: 0, 1, 2\r\n<\/pre>\n<h2>3. Array Length vs Number of Elements<\/h2>\n<p>It\u2019s a common misconception that an array\u2019s <strong>length<\/strong> is always equal to the number of elements it contains. In truth, the length of an array is determined by <strong>its highest index<\/strong>, not necessarily the quantity of its elements.<\/p>\n<p>The <strong>length property<\/strong> of an array is quite adaptable. Regardless of whether you\u2019ve set the array\u2019s length beforehand, adding more elements will increase the length correspondingly.<\/p>\n<pre>\r\n var myArray = [];\r\n myArray.length = 3;\r\n console.log(myArray.length);\r\n \/\/ 3\r\n \r\n myArray[5] = \"abcd\";\r\n console.log(myArray.length);\r\n \/\/ 6\r\n<\/pre>\n<p>In the example above, despite only adding one value at index 5, the array\u2019s length expands to 6. It\u2019s important to note that <strong>no indices from 0 to 4 are actually created<\/strong> in this process. This can be verified using the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/in\">in<\/a><\/code> operator.<\/p>\n<pre>\r\n var myArray = [];\r\n myArray.length = 3;\r\n console.log(myArray.length);\r\n \/\/ 3\r\n \r\n myArray[5] = \"abcd\";\r\n console.log(myArray.length);\r\n \/\/ 6\r\n \r\n console.log(0 in myArray);\r\n \/\/ false\r\n<\/pre>\n<p>The array <code>myArray<\/code> is what\u2019s known as a <strong>\u201csparse\u201d array<\/strong>, characterized by <strong>non-continuous indices<\/strong> and <strong>gaps<\/strong> between them. This is in contrast to a <strong>\u201cdense\u201d array<\/strong>, where indices are continuous and the number of elements equals the <code>length<\/code> property.<\/p>\n<p>The <code>length<\/code> property can also <strong>truncate an array<\/strong>, ensuring the highest index is always <strong>less than the length itself<\/strong>. This is because the length is, by default, numerically greater than the highest index, as detailed <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\/length\">here<\/a>.<\/p>\n<p>In the following example, observe how decreasing the <code>length<\/code> of array <code>myArray<\/code> leads to the loss of the element at index 5.<\/p>\n<pre>\r\n var myArray = [];\r\n myArray.length = 3;\r\n console.log(myArray.length);\r\n \/\/ 3\r\n \r\n myArray[5] = \"abcd\";\r\n console.log(myArray.length);\r\n \/\/ 6\r\n \r\n myArray.length = 2;\r\n console.log(myArray.length);\r\n \/\/ 2\r\n \r\n console.log(myArray[5]);\r\n \/\/ undefined\r\n<\/pre>\n<h2>Further Reading<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.hongkiat.com\/blog\/javascript-jargon\/\">10 JavaScript Terms You Should Know by Now<\/a><\/li>\n<li><a href=\"https:\/\/www.hongkiat.com\/blog\/useful-javascript-statements\/\">4 Not-So-Common But Helpful JavaScript Statements You Should Know<\/a><\/li>\n<li><a href=\"https:\/\/www.hongkiat.com\/blog\/code-optimisation-linting-jshint\/\">Code Optimisation with JS Hint \u2013 A Tool for Linting JavaScript<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features that aren\u2019t widely known. In this blog, we\u2019ll dive into three lesser-known but significant aspects of JavaScript arrays that may be new to you. 1. Adding Custom Features to Arrays&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[4117,511],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript Arrays and the 3 Things You Should Know - Hongkiat<\/title>\n<meta name=\"description\" content=\"Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/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 and the 3 Things You Should Know\" \/>\n<meta property=\"og:description\" content=\"Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-12T13:01:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-15T11:48:59+00:00\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"JavaScript Arrays and the 3 Things You Should Know\",\"datePublished\":\"2016-07-12T13:01:32+00:00\",\"dateModified\":\"2023-11-15T11:48:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/\"},\"wordCount\":887,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"Javascripts\",\"Web Developers\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/\",\"name\":\"JavaScript Arrays and the 3 Things You Should Know - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2016-07-12T13:01:32+00:00\",\"dateModified\":\"2023-11-15T11:48:59+00:00\",\"description\":\"Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/javascript-arrays\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Arrays and the 3 Things You Should Know\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript Arrays and the 3 Things You Should Know - Hongkiat","description":"Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features","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:\/\/www.hongkiat.com\/blog\/javascript-arrays\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Arrays and the 3 Things You Should Know","og_description":"Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features","og_url":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2016-07-12T13:01:32+00:00","article_modified_time":"2023-11-15T11:48:59+00:00","author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"JavaScript Arrays and the 3 Things You Should Know","datePublished":"2016-07-12T13:01:32+00:00","dateModified":"2023-11-15T11:48:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/"},"wordCount":887,"commentCount":3,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["Javascripts","Web Developers"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/","url":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/","name":"JavaScript Arrays and the 3 Things You Should Know - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2016-07-12T13:01:32+00:00","dateModified":"2023-11-15T11:48:59+00:00","description":"Arrays are common in programming; they are special types of variables that can hold many values at once. But JavaScript has some unique array features","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/javascript-arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript Arrays and the 3 Things You Should Know"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-6XU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/26778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=26778"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/26778\/revisions"}],"predecessor-version":[{"id":70294,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/26778\/revisions\/70294"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=26778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=26778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=26778"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=26778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}