同时使用两个数组可以通过以下几种方式实现:
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const combinedArray = array1.concat(array2);
console.log(combinedArray); // [1, 2, 3, 4, 5, 6]
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
array1.forEach((element, index) => {
console.log(element + array2[index]);
});
// 输出:
// 5
// 7
// 9
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const resultArray = array1.map((element, index) => {
return element + array2[index];
});
console.log(resultArray); // [5, 7, 9]
以上是使用两个数组的常见操作方式,具体使用哪种方式取决于实际需求。
领取专属 10元无门槛券
手把手带您无忧上云