[英]Is there any short way to slice an array from end to start without looping?
例如我有这个数组
[1,2,3,4]
我写了这段代码,但它也很长。 你能帮我找到一个更短的解决方案吗?
array.map((e,i)=>array[array.length-1-i])
如何在不使用反向方法并且使用比我的代码更短的方法的情况下反转数组。
let array = [1, 2, 3, 4]; //this is shorter but more expensive const reverse = array.sort(x => -1); console.log(...reverse); //if you want to keep the original array intact, make a copy of the array and then sort it //const reverse = [...array].sort(x => -1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.