Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6236843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:55:04+00:00 2026-05-24T10:55:04+00:00

In multiple browsers, the following code doesn’t sort the numbers correctly: a = new

  • 0

In multiple browsers, the following code doesn’t sort the numbers correctly:

a = new Array();
a.push(10);
a.push(60);
a.push(20);
a.push(30);
a.push(100);
document.write(a.sort())

It returns 10,100,20,30,60.

Anyone know why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:55:06+00:00Added an answer on May 24, 2026 at 10:55 am

    I’ve tried different numbers, and it always acts as if the 0s aren’t there and sorts the numbers correctly otherwise. Anyone know why?

    You’re getting a lexicographical sort (e.g. convert objects to strings, and sort them in dictionary order), which is the default sort behavior in Javascript:

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort

    array.sort([compareFunction])
    

    Parameters

    compareFunction

    Specifies a function that defines the sort order. If omitted, the array is sorted lexicographically (in dictionary order) according to the string conversion of each element.

    In the ECMAscript specification (the normative reference for the generic Javascript), ECMA-262, 3rd ed., section 15.4.4.11, the default sort order is lexicographical, although they don’t come out and say it, instead giving the steps for a conceptual sort function that calls the given compare function if necessary, otherwise comparing the arguments when converted to strings:

    13. If the argument comparefn is undefined, go to step 16.
    14. Call comparefn with arguments x and y.
    15. Return Result(14).
    16. Call ToString(x).
    17. Call ToString(y).
    18. If Result(16) < Result(17), return −1.
    19. If Result(16) > Result(17), return 1.
    20. Return +0.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple browsers on my android device. I can use the following code
I have the following code to read contents from a file to open multiple
In the following code: $(document).ready(function() { var content = ; for (var i =
We're developing this ASP.NET web app with multiple users on different browsers. One of
I'm developing a Firefox extension and have the following code: function initialize() { //
I'm trying to open multiple pages following a certain format using mechanize. I want
For an event we need the following setup: Multiple computers running a kinda of
I have a page with multiple select boxes, as per the following: <select name=item-0-status
Using YUICompressor I get the following error from my javascript code: [ERROR] 270:201:missing name
Hi i am using the following code to load a part of page dynamically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.