{"id":7210,"date":"2025-03-06T06:14:10","date_gmt":"2025-03-06T06:14:10","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7210"},"modified":"2025-03-06T06:14:12","modified_gmt":"2025-03-06T06:14:12","slug":"how-to-find-sum-of-array-of-numbers-in-javascript","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/","title":{"rendered":"How to Find Sum of Array of Numbers in JavaScript"},"content":{"rendered":"\n<p>JavaScript developers heavily depend on arrays to store numbers and text. JS arrays are easy to use, allow you to store data in a compact manner and offer many useful methods out of the box. Often web developers need to be able to sum all the items of an array. There are several ways to do this in JavaScript. In this article, we will learn how to find sum of array of numbers in JavaScript.<\/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-find-sum-of-array-of-numbers-in-javascript\/#How_to_Find_Sum_of_Array_of_Numbers_in_JavaScript\" >How to Find Sum of Array of Numbers in JavaScript<\/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-find-sum-of-array-of-numbers-in-javascript\/#1_Using_for_loop\" >1. Using for loop<\/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-find-sum-of-array-of-numbers-in-javascript\/#2_Using_forEach_method\" >2. Using forEach() method<\/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-find-sum-of-array-of-numbers-in-javascript\/#3_Using_reduce_function\" >3. Using reduce() function<\/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-find-sum-of-array-of-numbers-in-javascript\/#4_Using_recursion\" >4. Using recursion<\/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-find-sum-of-array-of-numbers-in-javascript\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Find_Sum_of_Array_of_Numbers_in_JavaScript\"><\/span>How to Find Sum of Array of Numbers in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are some of the most common ways to find sum of array of numbers in JavaScript.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_for_loop\"><\/span>1. Using for loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is the simplest way to sum items in an array. We initialize the sum of array to zero in a variable. Then we run a for loop over the array items and in each iteration we add the item to the sum. By the time the for loop exits, the sum variable will contain the value of sum of array items.<\/p>\n\n\n\n<p>Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var array = [1, 2, 3, 4, 5];<br>var sum = 0;<br>for (i = 0; i &lt; array.length; i++) {<br>    sum += array[i];<br>}<br>console.log(sum); \/\/ output is 15 <\/pre>\n\n\n\n<p>This method is very easy to understand and applicable for all arrays. You can also selectively choose the items you want to include\/exclude in the sum, by adding custom conditions in each iteration. Here is an example to sum only even numbers in an array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var array = [1, 2, 3, 4, 5];<br>var sum = 0;<br>for (i = 0; i &lt; array.length; i++) {<br>    if(array[i]%2 == 0){<br>      sum += array[i];<br>    }<br>}<br>console.log(sum); \/\/ output is 6<\/pre>\n\n\n\n<p>If your data contains non-numerical items then you can call a custom function to use 0 in its place, in every iteration. Here is an example where define a function isnum() to simply check if a variable is a number or not. If it is not a number, the function returns 0, else it returns the number itself.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var array = [1, 'a', 3, 'b', 5];<br>var sum = 0;<br>function isnum(n){<br>    return isNaN(n) ? 0 : n;<br>}<br>for (i = 0; i &lt; array.length; i++) {<br>    sum += isnum(array[i]);<br>    <br>}<br>console.log(sum); \/\/ output is 9<\/pre>\n\n\n\n<p>You can always define a function that accepts an array as an input argument and runs a for loop to calculate the sum of its elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = [1, 2, 3, 4, 5];<br>function sum(array){<br>    var sum = 0;<br>   for (i = 0; i &lt; array.length; i++) {<br>    sum += array[i];<br>  }<br>  return sum;<br>}<br>console.log(sum(a)); \/\/ output is 15 <\/pre>\n\n\n\n<p>You may also use other loop constructs like while to loop through the array and find sum of its elements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_forEach_method\"><\/span>2. Using forEach() method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Every JS array supports a built in method forEach() that can be called directly from the array. It allows you to define and call custom function for each item of the array. For example, you can initialize sum variable to 0 and use forEach() to loop through the array and sum each item to sum variable. Here is an example to demonstrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var array = [1, 2, 3, 4, 5];<br>var sum = 0;<br>array.forEach(x => {<br>    sum += x;<br>});<br><br>console.log(sum);<\/pre>\n\n\n\n<p>If you are not comfortable with using arrow functions as shown above, then you can also use traditional functions. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var total = 0;<br>var array = [1, 2, 3, 4, 5];<br><br>function my_sum(item) {<br>  total += item;<br>}<br>array.forEach(my_sum);<br><br>console.log(total);<\/pre>\n\n\n\n<p>In the above code, we have defined a JS function my_sum() that accepts an item and adds it to the total variable. We call this function in forEach() method. In this case, forEach() will run a loop over the items of array, and call my_sum() function on each item.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_reduce_function\"><\/span>3. Using reduce() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Every array also supports reduce() method that loops through the array and applies a reducer function to each item of the array. While doing so, it accumulates the result of each iteration and makes it available to the next iteration. Finally, it returns a single value. It does not run for empty arrays.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var array = [1, 2, 3, 4, 5];<br><br>let sum = array.reduce(function (x, y) {<br>    return x + y;<br>}, 0);<br><br>console.log(sum); \/\/ output is 15<\/pre>\n\n\n\n<p>In the above code, we define a function that adds 2 variables and returns the result. But it works differently than what is obvious. Initially, it adds the first 2 items and stores its result. In the next iteration, it adds the next item, that is, the 3rd item to this stored result, and so on. When it has gone through all items one by one, and added them to the result, it returns the result, which is stored in sum variable.<\/p>\n\n\n\n<p>The default sum or result is specified as 0, the second argument of reduce(). The first argument is the reducer function itself. If you do not specify the default value, then reduce() function will return undefined as the final result.<\/p>\n\n\n\n<p>Reduce method is similar to forEach except a few key differences. Reduce function specifically aggregates the values of an array and returns a single value in the end. forEach executes a specific function for each item of the array and does not return anything. Basically, reduce() function was created to reduce the array to a single value and return it.<\/p>\n\n\n\n<p>Compared to forEach(), using reduce() is faster and results in more compact code. This is because reduce() is specifically designed for aggregation and optimizes order of aggregation. On the other hand, forEach() will sequentially go through the array items, instead of using any other order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_recursion\"><\/span>4. Using recursion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Recursion is when you call a function inside its own definition, until it reaches a state where it cannot be called anymore. Here is an example to use a simple recursive function to sum items of array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var array = [1, 2, 3, 4, 5];<br>function sum(a, i) {<br>    if (i === array.length) {<br>        return 0;<br>    }<br>    return a[i] + sum(a, i + 1);<br>}<br>console.log(sum(array, 0));<\/pre>\n\n\n\n<p>In the above code, we define a function sum() that accepts an array and starting index=0. In each call, it returns the sum of array item present at index and the result of sum() function called on array along with index incremented by 1. This goes on until the index is equal to array&#8217;s length, that is, beyond the array items. At this point, it returns 0 and does not call sum() function any further.<\/p>\n\n\n\n<p>Please note, recursive functions are a little difficult to understand and also take up more memory, since each function call will need its own memory stack space. Also, if you do not define the termination condition of recursive function correctly, then it may forever keep calling the function one inside the other and crash.<\/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 several ways to find sum of array of numbers in JavaScript. We learnt how to add up all items of an array using a simple for loop. We also learnt how to do it using forEach() as well as reduce() functions. Lastly, we learnt how to find sum of array of numbers using recursion. We have covered several important use cases in each of these solutions. You can use any of these methods as per your requirement.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-search-for-object-in-array-of-objects-in-javascript\/\">How to Search Object in Array of Objects<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-add-new-elements-to-beginning-of-array-in-javascript\/\">How to Add New Elements to Beginning of JS Array<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-unique-values-in-javascript-array\/\">How to Get Unique Values in JavaScript<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.<\/p>\n","protected":false},"author":1,"featured_media":7239,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[393],"class_list":["post-7210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-sum-array"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Find Sum of Array of Numbers in JavaScript - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.\" \/>\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-find-sum-of-array-of-numbers-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Find Sum of Array of Numbers in JavaScript - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/\" \/>\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-06T06:14:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-06T06:14:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/find-sum-of-array-of-numbers-in-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"308\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\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-find-sum-of-array-of-numbers-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Find Sum of Array of Numbers in JavaScript\",\"datePublished\":\"2025-03-06T06:14:10+00:00\",\"dateModified\":\"2025-03-06T06:14:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/\"},\"wordCount\":1024,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1\",\"keywords\":[\"sum array\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/\",\"name\":\"How to Find Sum of Array of Numbers in JavaScript - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1\",\"datePublished\":\"2025-03-06T06:14:10+00:00\",\"dateModified\":\"2025-03-06T06:14:12+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1\",\"width\":308,\"height\":204,\"caption\":\"find sum of array of numbers in javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-find-sum-of-array-of-numbers-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Find Sum of Array of Numbers in JavaScript\"}]},{\"@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 Find Sum of Array of Numbers in JavaScript - Ubiq BI","description":"Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.","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-find-sum-of-array-of-numbers-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Find Sum of Array of Numbers in JavaScript - Ubiq BI","og_description":"Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-03-06T06:14:10+00:00","article_modified_time":"2025-03-06T06:14:12+00:00","og_image":[{"width":308,"height":204,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/find-sum-of-array-of-numbers-in-javascript.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-find-sum-of-array-of-numbers-in-javascript\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Find Sum of Array of Numbers in JavaScript","datePublished":"2025-03-06T06:14:10+00:00","dateModified":"2025-03-06T06:14:12+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/"},"wordCount":1024,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1","keywords":["sum array"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/","name":"How to Find Sum of Array of Numbers in JavaScript - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1","datePublished":"2025-03-06T06:14:10+00:00","dateModified":"2025-03-06T06:14:12+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes you may need to calculate sum of array items. Here are different ways to find sum of array of numbers in JavaScript.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1","width":308,"height":204,"caption":"find sum of array of numbers in javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Find Sum of Array of Numbers in JavaScript"}]},{"@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\/find-sum-of-array-of-numbers-in-javascript.jpg?fit=308%2C204&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Si","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7210","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=7210"}],"version-history":[{"count":27,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7210\/revisions"}],"predecessor-version":[{"id":7238,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7210\/revisions\/7238"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7239"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}