-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?

3
  • 1
    arr is an Array. Arrays don't have a .split() method. Also: RTFM. Commented Nov 26, 2014 at 10:53
  • @George! thank you very much.. i get it is now.. Commented Nov 26, 2014 at 10:58
  • possible duplicate of How can I reverse an array in JavaScript without using libraries? Commented Nov 26, 2014 at 11:01

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

updated to use your code
1

You can simply call the reverse() function of javascript

arr.reverse();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.