有人可以给我一个代码来反转JavaScript中的数组吗?

时间:2019-05-16 06:12:38

标签: javascript arrays reverse

反转数组并使用reduce和concat方法避免局部变量

代码:-

var reverse = function reverse() {
  let A = ["Hello", "world"];
  let B = A.reduceRight((a, c) => (a.push(c), a), []);
  console.log(B);
};

reverse()

1 个答案:

答案 0 :(得分:-1)

使用reverse()函数反转数组

var reverse = function reverse() {
  let A = ["Hello", "world"];
  console.log(A.reverse())
};

reverse()