<div id="ok" ></div>
<br/>
<button type="button" id="ok" onclick="ok(i,j)">Click</button>
<script type="text/javascript">
var unit = ["1","2","8","9"];
var unit1= ["3","4","6","7"];
var i=0;
var j=0;
function ok(i,j) {
if(i>unit.length-1){alert("Массив закончился!"); return;}
document.getElementById("ok").innerHTML='unit['+i+']+unit['+j+']='+ (+unit[i] + +unit1[j]);
window.i++; window.j++;
}
</script>