Search code examples
javascriptarrayswebstormreversemirror

Mirror a literal array in WebStorm


I got a literal JavaScript array in WebStorm.

//example
var arr = [9,7,5,3,1];

I want to mirror that array in editor, the result should be like this.

//result
var arr = [1,3,5,7,9];

I don't want to sort the array, but mirror its values.


Solution

  • Simply use JavaScript reverse().

    var arr = [9,7,5,3,1];
    arr.reverse();
    console.log(arr);