Answers for "javascript reverse"

14

javascript string reverse

"this is a test string".split("").reverse().join("");
//"gnirts tset a si siht"

// Or
const reverse = str => [...str].reverse().join('');

// Or
const reverse = str => str.split('').reduce((rev, char)=> `${char}${rev}`, '');

// Or
const reverse = str => (str === '') ? '' : `${reverse(str.substr(1))}${str.charAt(0)}`;

// Example
reverse('hello world');     // 'dlrow olleh'
Posted by: Guest on July-02-2020
33

javascript reverse array

var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);
Posted by: Guest on November-16-2019
10

.reverse javascript

const array1 = [1,2,3,4];
console.log('array1:', array1);
//"array1:" Array [1, 2, 3, 4]

const reversed = array1.reverse();
console.log('reversed:', reversed);
//"reversed:" Array [4, 3, 2, 1]

// Careful: reverse is destructive -- it changes the original array.
console.log('array1:', array1);
//"array1:" Array [4, 3, 2, 1]
Posted by: Guest on September-21-2021
7

reverse array javascript

var rev = arr.reverse();
Posted by: Guest on April-01-2020
5

reverse array javascript

const list = [1, 2, 3, 4, 5];
list.reverse();
Posted by: Guest on August-28-2020
1

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);
Posted by: Guest on April-26-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language