arr1 = ['lot','lol', 'lov', 'lor', 'lou','lop' ,'loh'];
arr2 = [1,2,3,4,5,6,7,8,9,10]
var id = 0;
for(let idx = 0; idx < arr1.length; idx++ ){
a = arr1[idx];
b1 = arr2[id];
c1 = arr2[id+1];
alert('name: '+a+' val1: '+b1+' val2: '+c1);
if(arr2[id+2] && arr2[id+3]){
id++
id++
}
}
const result = arr1.map((n, i) => {
const index = Math.min(i * 2, ((arr2.length - 2) / 2 | 0) * 2);
return `name: ${n} val1: ${arr2[index]} val2: ${arr2[index + 1]}`;
});
result.forEach(alert);
const len1 = arr1.length;
const top2 = 2 * Math.floor((arr2.length - 2) / 2);
for (let id1 = 0, id2 = 0; id1 < len1; id1++, id2 = Math.min(top2, id2 + 2)) {
console.log(`name: ${arr1[id1]} val1: ${arr2[id2]} val2: ${arr2[id2 + 1]}`);
}
arr1
и arr2
, индексы по ним, соотв., хорошо назвать с теми же номерами: id1
и id2
arr1.slice(0, arr2.length - 1).forEach((name, id) => {
console.log(`name: ${name} val1: ${arr2[id]} val2: ${arr2[id + 1]}`);
});