任务是用JavaScript创建以下数组。
[
["HTML", 4],
["CSS", 3],
["JavaScript", 10],
["React", 5],
["Redux", 5],
["Node", 4],
["MongoDB", 7]
]
它实际上是打印输出,但不是在括号内。请帮助我们。
for(let i = 0; i < webTechs.length; i++){
arr.push(webTechs[i], webTechs[i].length)
}
console.log(arr)
由于你期待的是一个数组,你需要把元素本身作为数组推送。
for(let i = 0; i < webTechs.length; i++){
arr.push([webTechs[i], webTechs[i].length]) //Notice the [] to push them as array into 'arr'
}