JSFiddle - React, Tailwind, and code Playground

by karan shah

HTML

<input type="submit" id="byBtn" value="GetSum" onclick="getValue()"/>
<span id="result"></span>

JavaScript

var sum =0;
function getValue(){
    var data = [[[1,2,3,4,5],[[1],[2],[3],[4],[5],[6],[[1]]],[9,8,7,6,5,[1,2,3]]],[10,20,30,40,50],[21,33,55,66,77,88],[11,12,13,14,15,16,17,18,19],[[1000,[1234]],154,2122],[45,66,88,99,100,101]];
    
    getSum(data);
    document.getElementById("result").innerHTML = sum;
}

//Recursivle keep on adding the values. If item is an array
//perform the same fucntion to get its value and add to sum
function getSum(data){
	for(var i=0;i<data.length;i++){
		var temp = data[i];
		if(temp instanceof Array){
			start2(temp);
		}else{
			sum=sum+temp;
		}
	}
}