JavaScript 数组逆序遍历:从后往前获取元素
可以使用for循环和数组的 length 属性实现:
let rest = ['1', '2', '3'];
for (let i = rest.length - 1; i >= 0; i--) {
console.log(rest[i]);
}
输出结果为:
3
2
1
原文地址: https://www.cveoy.top/t/topic/iq0N 著作权归作者所有。请勿转载和采集!
安全问答是一个知识全球问答,包含丰富的问答知识
可以使用for循环和数组的 length 属性实现:
let rest = ['1', '2', '3'];
for (let i = rest.length - 1; i >= 0; i--) {
console.log(rest[i]);
}
输出结果为:
3
2
1
原文地址: https://www.cveoy.top/t/topic/iq0N 著作权归作者所有。请勿转载和采集!