Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Without using a new array or the reverse() method to Reverse an Array

var arr = [1, 2, 3, 4];
for (let i = 0; i < Math.floor(arr.length / 2); i++) {
    [arr[i], arr[arr.length - 1 - i]] = [arr[arr.length - 1 - i], arr[i]];
}
console.log(arr);
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Without #array #method #Reverse #Array
ADD COMMENT
Topic
Name
2+1 =