- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript recursive loop to sum all integers from nested array?
You need to call the same function again and again to sum all integers from nested array. Following is the code −
Example
function sumOfTotalArray(numberArray){ var total= 0; for (var index = 0; index < numberArray.length; index++) { if (numberArray[index] instanceof Array){ total=total+sumOfTotalArray(arr[index]); } if (numberArray[index] === Math.round(numberArray[index])){ total=total+numberArray[index]; } } return total; } var number = new Array(6); number=[10,20,30,40,50,60]; console.log("The sum is="+sumOfTotalArray(number));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo53.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo53.js The sum is=210
- Related Articles
- How to sum all elements in a nested array? JavaScript
- Recursion - Sum Nested Array in JavaScript
- Recursive sum all the digits of a number JavaScript
- Weight sum of a nested array in JavaScript
- How to use nested while loop in JavaScript?
- How to use nested for loop in JavaScript?
- Sum of nested object values in Array using JavaScript
- How to set attribute in loop from array JavaScript?
- Recursive loop that prints an inverted count in JavaScript
- JavaScript - summing numbers from strings nested in array
- Recursive multiplication in array - JavaScript
- Transform data from a nested array to an object in JavaScript
- Convert nested array to string - JavaScript
- Simplifying nested array JavaScript
- Sum all duplicate value in array - JavaScript

Advertisements