Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js function call itself

// JavaScript Recursive Function:
// A recursive function is a function that calls itself until it doesn't.
function sumArray(array) {
  let sum = 0;
  for (const item of array) {
    sum += Array.isArray(item) ? sumArray(item) : item;
  }
  return sum;
}
sumArray([1, [4, 6]]); // => 11
Source by w3programmers.org #
 
PREVIOUS NEXT
Tagged: #js #function #call
ADD COMMENT
Topic
Name
2+3 =