Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

reverse array without using another array js

let arr = [1, 2, 3, 4, 5, 6, 7];
let n = arr.length-1;

for(let i=0; i<=n/2; i++) {
  let temp = arr[i];
  arr[i] = arr[n-i];
  arr[n-i] = temp;
}
console.log(arr);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #reverse #array #array #js
ADD COMMENT
Topic
Name
1+4 =