-2

I need to know if exits some incorporated method in Javascript that turn from back to front a array or I have to create it

example

var fruits = ["Banana", "Orange", "Apple", "Mango"];

to

var fruits = ["Mango","Apple","Orange","Banana"];
2
  • Duplicate of stackoverflow.com/questions/5276953/…
    – Etheryte
    Dec 4, 2014 at 23:04
  • 1
    The title of your question does not match the content. Do you want to impose an ordering based on the values in the array, or do you simply want to reverse the existing order?
    – Pointy
    Dec 4, 2014 at 23:06

1 Answer 1

5

You could just use the reverse method.

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.reverse();

Please have a look at this fiddle.

4
  • Why was this downvoted, I wonder? It doesn't match the title but it does match the content of the post.
    – Pointy
    Dec 4, 2014 at 23:04
  • Restored justice on both
    – zerkms
    Dec 4, 2014 at 23:05
  • @Pointy thank you very much for your comment. At least someone had the same question like me.
    – Christos
    Dec 4, 2014 at 23:07
  • Thanks Christos. I get confused. I thought that reverse order the array in descendent order and alphabetical Dec 4, 2014 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.