Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Using a decrementing For Loop to Reverse an Array

var arr = [1, 2, 3, 4];
var arr1 = [];
for (let i = arr.length - 1; i >= 0; i--) {
    arr1.push(arr[i]);
}
console.log(arr1);
Comment

array reverse with for loop

function reverseArray (arr) {
    var newArr = [];
    var inArr = arr;
    console.log(inArr);
    for (i = 0; i < arr.length; i++) {      
        newArr[i] = inArr.pop(i);       
    }   
    return newArr;
}
reverseArray(["A", "B", "C", "D", "E", "F"]);

// OUTPUT: ["F", "D", "E"]
Comment

PREVIOUS NEXT
Code Example
Javascript :: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.6/$injector/modulerr?p0=myApp 
Javascript :: react hooks link to external site 
Javascript :: remove an item from the end of an array 
Javascript :: string js 
Javascript :: how to check if date is between two dates in javascript 
Javascript :: paypal in react js 
Javascript :: compare if strings are equal javascript 
Javascript :: custom search filter in angular 8 
Javascript :: prompt in javascript 
Javascript :: javascript strings vs numbers 
Javascript :: react native fontsize not affected by phone settings 
Javascript :: calcular sobra de divisão de parcelas js 
Javascript :: vue 3 $refs 
Javascript :: js how to to attach an event handler only once 
Javascript :: Add Multilanguage Support to React App 
Javascript :: javascript switch statement 
Javascript :: nohup nodemon 
Javascript :: new date.gettime() is not a constructor 
Javascript :: create angular app with routing 
Javascript :: how to get ip address and port from url in javascript 
Javascript :: buscar una frase e un string js 
Javascript :: js split method 
Javascript :: d3.js click event 
Javascript :: react google places auto complete example 
Javascript :: how to filter multiple values from a json api 
Javascript :: formdata 
Javascript :: classic asp json multidemsion json 
Javascript :: function expression javascript 
Javascript :: dropzone upload on one file 
Javascript :: nestjs prisma on query 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =