How can I reverse an array in JavaScript without using libraries?

前端 未结 30 1293

I am saving some data in order using arrays, and I want to add a function that the user can reverse the list. I can\'t think of any possible method, so if anybo

30条回答
  •  天命终不由人
    2020-11-27 06:16

    function reverseArray(arr) {
        let reversed = [];
        for (i = 0; i < arr.length; i++) { 
        reversed.push((arr[arr.length-1-i]))
        }
      return reversed;
    }
    

提交回复
热议问题