“Wie man das Array in JavaScript umkehrt” Code-Antworten

JavaScript Reverse Array

var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);
Black Footed Ferret

Array Reverse -Algorithmus in JS

let array1 = ["yes", "no", "maybe", "always", "sometimes", "never", "if"];
let array2 = [5,8,2,9,5,6,3,1];

function reverseArray(arr) {
  var newArray = [];
  for (var i = arr.length - 1; i >= 0; i--) {
    newArray.push(arr[i]);
  }
  return newArray;
}

reverseArray(array1); // ["if", "never", "sometimes", "always", "maybe", "no", "yes"]
reverseArray(array2); // [1, 3, 6, 5, 9, 2, 8, 5]
Salo Hopeless

JS -Array umgekehrt

const arr = [34, 234, 567, 4];
console.log(arr);
const new_arr = arr.reverse();
console.log(new_arr);
Envious Eel

wie man ein Array umkehrt

        int[] xr = {1, 2, 3, 4, 5};

        System.out.print("[");
        for (int i = xr.length - 1; i >= 0; i--) {
            System.out.print(xr[i] + ", ");
        }
        System.out.println("\b\b]");
    }
Chathumal Sangeeth

Wie man das Array in JavaScript umkehrt

// reversing an array in javascript is kinda hard. you can't index -1.
// but i can show how you can do it in 4 lines.

var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

for (var i = myArray.length - 1; i > 0; i -= 1) {
	myArray.shift();
	myArray.push(i);
}

console.log(myArray); // output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
tomiha

Wie man das Array in JavaScript umkehrt

numArr.reverse();
strArr.reverse();

console.log(numArr);
console.log(strArr);
Shubham Rajput

Ähnliche Antworten wie “Wie man das Array in JavaScript umkehrt”

Fragen ähnlich wie “Wie man das Array in JavaScript umkehrt”

Weitere verwandte Antworten zu “Wie man das Array in JavaScript umkehrt” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen