var arr = [1,2,null,3,,4,5]; var sum = 0; for ( var key in arr ){ sum += Math.pow(arr[key], 2) || 0; } alert(sum);