{"id":7432,"date":"2025-03-25T07:06:32","date_gmt":"2025-03-25T07:06:32","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7432"},"modified":"2025-03-25T07:06:35","modified_gmt":"2025-03-25T07:06:35","slug":"how-to-remove-empty-elements-from-javascript-array","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/","title":{"rendered":"How to Remove Empty Elements from JavaScript Array"},"content":{"rendered":"\n<p>Web developers commonly rely on arrays to store and manipulate data. Often these arrays contain empty elements. An empty element is one which does not have any value, not even undefined or null. Such elements can cause issues in your program, if not handled beforehand. In this article, we will learn how to remove empty elements from JavaScript array.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#Why_Remove_Empty_Elements\" >Why Remove Empty Elements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#How_to_Remove_Empty_Elements_from_JavaScript_Array\" >How to Remove Empty Elements from JavaScript Array<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#1_Using_Filter_Function\" >1. Using Filter Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#2_Using_Flat_Method\" >2. Using Flat Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#3_Using_Splice_Method\" >3. Using Splice Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#4_Using_Reduce_Method\" >4. Using Reduce Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#5_Using_Push_Method\" >5. Using Push Method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#6_Using_jQuery\" >6. Using jQuery<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Remove_Empty_Elements\"><\/span>Why Remove Empty Elements<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Empty elements are those array elements that do not contain any value. When we import data from a file or other system, it is common for the data to contain empty values. Sometimes, when you convert another data type such as JSON string to an array, it can also result in empty elements. For example, the array a = [1, , 3] contains an empty element after 1 and before 3. Such elements can cause errors in your JavaScript code. For example, if you are processing every element of the array and your code does not factor empty elements, then it can cause an error and terminate execution. Therefore, it is important to remove empty elements from your JavaScript array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Remove_Empty_Elements_from_JavaScript_Array\"><\/span>How to Remove Empty Elements from JavaScript Array<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to remove empty elements from JavaScript array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Filter_Function\"><\/span>1. Using Filter Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Every JavaScript array supports filter method, that allows you to create a new array from another array, based on elements that satisfy one or more conditions. There are several ways to use filter function to remove empty elements from array.<\/p>\n\n\n\n<p>Let us say you have the following JS array with empty elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, '', null, 3, undefined, 4];<\/pre>\n\n\n\n<p>Here are some of the ways to use filter function to remove empty elements.<\/p>\n\n\n\n<p>You can define a simple function that returns the given element. In this case, it will return only truth values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">let a1 = a.filter(function (e) {<br>    return e; <br>});<br><br>console.log(a1); \/\/ output is [1, 2, 3, 4]<\/pre>\n\n\n\n<p>You can shorten it using arrow function as shown.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.filter(n=>n)); \/\/ output is [1, 2, 3, 4]<\/pre>\n\n\n\n<p>Alternatively, you can also define a filter function that checks if each element of the array is true or false, that is non empty or empty. It will also return an array of non-empty elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.filter(Boolean)); \/\/ output is [1, 2, 3, 4]<\/pre>\n\n\n\n<p>You can also put a condition that checks if the element is a Number or not.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.filter(Number)); \/\/ output is [1, 2, 3, 4]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Flat_Method\"><\/span>2. Using Flat Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the above method, the filter function removes not only empty items but also items that are null or undefined. Sometimes, you may want to remove only empty items and retain the rest. In such cases, you can use flat method available for every array. Here is an example to illustrate the difference between this solution and the above one.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, , '', null, 3, undefined, 4];<br>console.log(a.flat()); \/\/ output is [ 1, 2, '', null, 3, undefined, 4 ]<\/pre>\n\n\n\n<p>The above solution removes only empty items but retains empty strings, numbers and items that are undefined.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_Splice_Method\"><\/span>3. Using Splice Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Splice method is used to add\/remove one or more items in an array. It can also be used to remove empty items from the array. Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, , '', null, 3, undefined, 4];<br>for (let i = a.length - 1; i >= 0; i--) {<br>    if (!a[i]) {<br>        a.splice(i, 1);<br>    }<br>}<br>console.log(a); \/\/ output is [ 1, 2, 3, 4 ]<\/pre>\n\n\n\n<p>In the above code, we iterate through the array in reverse order. In each iteration, we check if the item is empty or not. If the item is empty, then we call splice function to remove the item. You can customize it to  remove only specific items in an array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_Reduce_Method\"><\/span>4. Using Reduce Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Generally, reduce method is used to reduce an array to a single value but it can also be used to remove empty items from array. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">array.reduce( function(total, current_value, current_index, array), initial_value )<\/pre>\n\n\n\n<p>Here is an example to use reduce method to remove empty items from array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, , '', null, 3, undefined, 4];<br>var a1 = a.reduce( (acc, e)=> {<br>    if (e) { <br>        acc.push(e);<br>    }<br>    return acc;<br>}, []); <br><br>console.log(a1); \/\/ output is [1, 2, 3, 4]<\/pre>\n\n\n\n<p>In the above code, we first initiate an empty array. Then we call reduce method on every array item of array <em>a<\/em>. In each call, we check if item exists or not. If it exists, we push it into array a1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_Push_Method\"><\/span>5. Using Push Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Push function is used to push an item into a JavaScript array. You can also use it to remove empty items.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, , '', null, 3, undefined, 4];<br>var a1=[];<br>a.forEach((element) => {<br>    if (element) {<br>        a1.push(element);<br>    }<br>});<br>console.log(a1); \/\/ output is [ 1, 2, 3, 4 ]<\/pre>\n\n\n\n<p>In the above method, we call forEach() method for the array, to loop through the items of array. In each iteration, we first check if the element exists or is empty. If it exists, then we push it into a1 array. This solution will also remove empty strings, nulls and undefined items.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_jQuery\"><\/span>6. Using jQuery<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>jQuery is a popular third party JavaScript library that contains many useful functions for data and DOM manipulation. It provides grep function that can be used for our purpose. It is similar to filter() function and removes items that do not match a given search criteria. Here is an example to remove empty items from array, using grep function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, , '', null, 3, undefined, 4];<br>var a1 = a.reduce( (acc, e)=> {<br>    \/\/ Check if the current element is truthy<br>    if (e) { <br>        acc.push(e);<br>    }<br>    return acc;<br>}, []); \/\/ Initialize acc as empty array<br><br>console.log(a1); \/\/ output is [1, 2, 3, 4]<\/pre>\n\n\n\n<p>In the above code, we define a reducer function that is called for each array item. In each call, it checks if the item exists or not. If it exists, then the item&#8217;s copy is pushed to array a1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt many different ways to easily remove empty items from array. The simplest way to remove empty items is to use filter method. But this method will also remove nulls, undefined and empty strings. If you do not want to remove these items but only empty items, then you can call flat() function available for every array. It will only remove empty items but not affect nulls, empty strings or items with undefined value. If you want to customize the removal <\/p>\n\n\n\n<p>Also read:<br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-detect-invalid-date-in-javascript\/\">How to Detect Invalid Date in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/\">How to Find Sum of Array of Numbers in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-search-for-object-in-array-of-objects-in-javascript\/\">How to Search for Object in Array of Objects in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.<\/p>\n","protected":false},"author":1,"featured_media":7454,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[400],"class_list":["post-7432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-remove-empty-elements"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Remove Empty Elements from JavaScript Array - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Remove Empty Elements from JavaScript Array - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-25T07:06:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-25T07:06:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"288\" \/>\n\t<meta property=\"og:image:height\" content=\"192\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\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:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Remove Empty Elements from JavaScript Array\",\"datePublished\":\"2025-03-25T07:06:32+00:00\",\"dateModified\":\"2025-03-25T07:06:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/\"},\"wordCount\":900,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1\",\"keywords\":[\"remove empty elements\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/\",\"name\":\"How to Remove Empty Elements from JavaScript Array - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1\",\"datePublished\":\"2025-03-25T07:06:32+00:00\",\"dateModified\":\"2025-03-25T07:06:35+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1\",\"width\":288,\"height\":192,\"caption\":\"remove empty items from javascript array\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-remove-empty-elements-from-javascript-array\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Remove Empty Elements from JavaScript Array\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Remove Empty Elements from JavaScript Array - Ubiq BI","description":"Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.","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:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/","og_locale":"en_US","og_type":"article","og_title":"How to Remove Empty Elements from JavaScript Array - Ubiq BI","og_description":"Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-03-25T07:06:32+00:00","article_modified_time":"2025-03-25T07:06:35+00:00","og_image":[{"width":288,"height":192,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Remove Empty Elements from JavaScript Array","datePublished":"2025-03-25T07:06:32+00:00","dateModified":"2025-03-25T07:06:35+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/"},"wordCount":900,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1","keywords":["remove empty elements"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/","name":"How to Remove Empty Elements from JavaScript Array - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1","datePublished":"2025-03-25T07:06:32+00:00","dateModified":"2025-03-25T07:06:35+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to remove empty elements from JavaScript array. Here are the different ways to do this.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1","width":288,"height":192,"caption":"remove empty items from javascript array"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Remove Empty Elements from JavaScript Array"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/remove-empty-items-javascript-array.jpg?fit=288%2C192&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1VS","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7432"}],"version-history":[{"count":22,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7432\/revisions"}],"predecessor-version":[{"id":7455,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7432\/revisions\/7455"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7454"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}