how to reverse a function in javascript code example
Example 1: javascript string reverse
"this is a test string".split("").reverse().join("");
const reverse = str => [...str].reverse().join('');
const reverse = str => str.split('').reduce((rev, char)=> `${char}${rev}`, '');
const reverse = str => (str === '') ? '' : `${reverse(str.substr(1))}${str.charAt(0)}`;
reverse('hello world');
Example 2: javascript reverse array
var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);
Example 3: js how to reverse a string
function reverseString(s){
return s.split("").reverse().join("");
}
reverseString("Hello");
Example 4: js reverse
const array1 = ['one', 'two', 'three'];
console.log('array1:', array1);
const reversed = array1.reverse();
console.log('reversed:', reversed);
console.log('array1:', array1);
Example 5: reverse an array javascript
const reversed = array1.reverseconst reversed = array1.reverse();
console.log('reversed:', reversed);
console.log('reversed:', reversed);
console.log('reversed:', reversed);