reverse array index position in array of array in JS

i Have a array

var arr = [["25","98"],["28","94"],["24","91"]]

how to make this array like in JS

var Newarr = [["98","25"],["94", "28"],["91", "24"]]

3 answers

  • answered 2018-03-11 12:42 Eddie

    You can use map to reiterate the array. You can spread [...v] each array to make a new array (and won't affect the original array). Use reverse to reverse it.

    var arr = [["25","98"],["28","94"],["24","91"]];
    var Newarr = v=> [...v].reverse() );

  • answered 2018-03-11 12:42 Nenad Vracar

    You can use map() and slice() to create new array and copy each sub-array inside and then and reverse() method.

    var arr = [["25","98"],["28","94"],["24","91"]]
    const reverse = => e.slice().reverse());

    You could also do this with map() and reduceRight() methods.

    var arr = [["25","98"],["28","94"],["24","91"]]
    const reverse = => e.reduceRight((r, e) => r.concat(e), []));

  • answered 2018-03-11 12:42 connexo

    Use and a sequence of Array.prototype.slice thenArray.prototype.reverse:

    let arr = [["25","98"],["28","94"],["24","91"]]
        x => x.slice().reverse()

    If you omit the slice() then the .reverse() changes the original arr.