var arr = [1,2,null,3,,4,5]; var Summ = eval(arr.join(',').replace(/(?:^|,)(\d*)/ig,'+$1*$1').replace(/\*\+/g,'')) alert(Summ)