inverter array js code example
Example 1: js array reverse
[34, 234, 567, 4].reverse();
Example 2: array reverse in javascript
var arr = [1, 2, 3, 4, 5, 6, 7];
console.log (arr.reverse ());
for (i = 0; i < arr.length / 2; i++) {
var temp = arr[i];
temp =arr[arr.length - 1 - i];
temp = temp;
}
console.log (arr);
Example 3: reverse array javascript
function reverseArray (arr){
if (arr.length === 0){
return []
}
return [arr.pop()].concat(reverseArray(arr))
}
console.log(reverseArray([1, 2, 3, 4, 5]))
Example 4: reverse an array javascript
const reversed = array1.reverseconst reversed = array1.reverse();
console.log('reversed:', reversed);
console.log('reversed:', reversed);
console.log('reversed:', reversed);