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

  • SEARCH
  • Home
  • 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 8413679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:57:51+00:00 2026-06-10T00:57:51+00:00

I was working on some code where I need to perform an alphabetic ascending

  • 0

I was working on some code where I need to perform an alphabetic ascending sort (standard .sort()) behavior and I wondered how sorting works with special characters and characters from different character sets. For example:

var aChars = [];

aChars.push("¢");
aChars.push("™");
aChars.push("È");
aChars.push("~");
aChars.push("p");
aChars.push("_");
aChars.push("P");
aChars.push("治");
aChars.push("す");

aChars.sort();

for (var i = 0;i<aChars.length;i++) {
    console.log(aChars[i]);
    //alert(aChars[i]);   
}​

I always get a consistent order when I execute this code. How does JavaScript decide the order? I thought it might be by HTML entity number, but I can’t find an HTML entity number for those Japanese characters.

  • 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-06-10T00:57:52+00:00Added an answer on June 10, 2026 at 12:57 am

    If you don’t provide your own comparision function, then per the ECMAScript spec, here are the rules:

    1. If x and y are both undefined, return +0.
    2. If x is undefined, return 1.
    3. If y is undefined, return -1.
    4. If the argument comparefn was not provided in the call to sort, go to step 7.
    5. Call comparefn with arguments x and y.
    6. Return Result(5).
    7. Call ToString(x).
    8. Call ToString(y).
    9. If Result(7) < Result(8), return -1.
    10. If Result(7) > Result(8), return 1.
    11. Return +0.

    For your particular case, it is determined by steps 7-11.

    And, the < and > operators compare the Unicode encoding value of the first differing character.

    For finer grain control over the situation, MDN recommends using your own custom compare function that uses String.localeCompare() which contains a bit smarter logic for sorting characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on some code were I need to add a Node into
here is some code I've been working on, basically I need to set up
I need to import some ANSI C code into a project I'm working on.
Need some regular expressions help. So far I have my code working to allow
Hey all i am in need of some help getting my code working correctly
I'm working some code that inserts csv rows into an SQLite database using Python.
I've been re-working some code due to a memory leak. The code is part
Working on some code for a machine problem; we've just started working with pointers,
I'm working on some code that reads from a socket, and it goes wrong
I'm working on some code to insert a link to a dupe in the

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.