var arr = [1,2,null,3,,4,5]; function s(x){ return sum += x*x; }; var sum = 0; for(var keys = 0;keys<arr.length;keys++){ if(!arr[keys]) continue; var xx = arr[keys]; s(xx); }; alert('Summa = ' + sum);