arr1 = [1,2]arr2=[1,2,3,4,5,6]用javascript的方式将以上两组数据处理成 1:1,2:2,3:1,4:2,5:1,6:2

const arr1 = [1, 2];
const arr2 = [1, 2, 3, 4, 5, 6];

const length1 = arr1.length;
const length2 = arr2.length;
const maxLength = Math.max(length1, length2);

for (let i = 0; i < maxLength; i++) {
  const item1 = arr1[i % length1];
  const item2 = arr2[i % length2];
  console.log(`${item2}:${item1}`);
}

你可能感兴趣的:(javascript,前端)