如何将两个数组中的数,两两一组(数组)放进一个大数组中
原数组
const arr1 = [10,20,30,40,50]
const arr2 = [11,22,33,44,55]
要求效果
const result = [
[10,11],
[20,22],
[30,33],
[40,44],
[50,55]
]
如何将两个数组中的数,两两一组(数组)放进一个大数组中
原数组
const arr1 = [10,20,30,40,50]
const arr2 = [11,22,33,44,55]
要求效果
const result = [
[10,11],
[20,22],
[30,33],
[40,44],
[50,55]
]
回答:还是容易实现的
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
const arr1 = [10, 20, 30, 40, 50]
const arr2 = [11, 22, 33, 44, 55]
const result = []
for (var i = 0; i < arr1.length; i++) {
var tempArr = []
tempArr.push(arr1[i])
tempArr.push(arr2[i])
result.push(tempArr)
}
console.log(result);
</script>
</body>
</html>