-3

how use javascript

reverse array

i wanted it is("861", "860","859","858" ............. )

    var arr = [
                "803", "812", "828", "846", "851",
                "852", "853", "857", "858", "859", "860", "861"
               ];
    var splitarr = arr.split(",");
     for (var i = 0; i < arr.length; i++){
        console.log(splitarr);
     }

it is java arrays?

Kisspa
  • 584
  • 4
  • 11
  • 1
    `arr` is an Array. Arrays don't have a `.split()` method. Also: [RTFM](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse). – George Nov 26 '14 at 10:53
  • @George! thank you very much.. i get it is now.. – Kisspa Nov 26 '14 at 10:58
  • possible duplicate of [How can I reverse an array in JavaScript without using libraries?](http://stackoverflow.com/questions/10168034/how-can-i-reverse-an-array-in-javascript-without-using-libraries) – bud-e Nov 26 '14 at 11:01

3 Answers3

2

Simply: reverse()

The reverse() method reverses an array in place. The first array element becomes the last and the last becomes the first.

var arr = [
                "803", "812", "828", "846", "851",
                "852", "853", "857", "858", "859", "860", "861"
               ];
arr.reverse();
console.log(arr);

DEMO

Manwal
  • 23,450
  • 12
  • 63
  • 93
1

Array has a reverse function on it's prototype.

var arr = [
                "803", "812", "828", "846", "851",
                "852", "853", "857", "858", "859", "860", "861"
               ];
arr.reverse()

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse

vernak2539
  • 574
  • 3
  • 14
1

You can simply call the reverse() function of javascript

arr.reverse();