“Array Reverse -Algorithmus in JS” 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

Ähnliche Antworten wie “Array Reverse -Algorithmus in JS”

Fragen ähnlich wie “Array Reverse -Algorithmus in JS”

Weitere verwandte Antworten zu “Array Reverse -Algorithmus in JS” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen