<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<script src="https://nervgh.github.io/js/recursive-iterator.min.js"></script>
<script>
man=Array();
man[0]=Array();
man[0][0]="30";
man[0][1]="40";
man[0][2]="50";
man[0][3]="50";
man[0][4]="40";
//---------------------------------------------------------
man[1]=Array();
man[1][0]="20";
man[1][1]="31";
man[1][2]="31";
man[1][3]="351";
man[1][4]="31";
//---------------------------------------------------------
man[2]=Array();
man[2][0]="123";
man[2][1]="123";
man[2][2]="51";
man[2][3]="190";
man[2][4]="87";
//---------------------------------------------------------
man[3]=Array();
man[3][0]="22";
man[3][1]="56";
man[3][2]="1000";
man[3][3]="220";
man[3][4]="100";
var iterator = new RecursiveIterator(man),
sum = 0;
for(var item = iterator.next(); !item.done; item = iterator.next()) {
var state = item.value;
if (state.key == 4 && state.deep == 2 ) sum += +state.node
}
alert(sum)
</script>
</body>
</html>