用嵌套循环JavaScript逆转子阵列
我想用带有嵌套循环的子阵列逆转数组。我不想使用反向函数。但是每次我这样做时,我都会得到一个类型。
无论如何,这是我的代码,
let arr = [[1,2,3],[4,5,6],[7,8,9]];
for(let i = arr.length - 1; i > 0; i--)
{
for (let j = arr[i].lenght - 1; j > 0; j--)
{
console.log(arr[i][j]);
}
}
结果应该是9,8,7,6,5,4,3,2,1,但是我什么也没空。
I wants to reverse the array with sub arrays with nested loops. I do not wants to use the reverse function. But every-time I do that I get this a type-error.
anyways here is my code
let arr = [[1,2,3],[4,5,6],[7,8,9]];
for(let i = arr.length - 1; i > 0; i--)
{
for (let j = arr[i].lenght - 1; j > 0; j--)
{
console.log(arr[i][j]);
}
}
The result should be 9,8,7,6,5,4,3,2,1 but instead I get nothing blank.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可以使用降低
让我知道它是否适合您
You can use this also, using reduce
let me know if it works for you or not
您在单词
length
中都有错别字,并且应该是> = 0
You had a typo in the word
length
and also it should be>= 0