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 7080583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:48+00:00 2026-05-28T06:48:48+00:00

How to output this JSON element in correct order by it’s value? var json

  • 0

How to output this JSON element in correct order by it’s value?

var json = { 
    "message": {
        "90": "Adidas", 
        "2": "Armani", 
        "89": "Casio", 
        "1": "Diesel", 
        "72": "DKNY", 
        "88": "Fossil", 
        "4": "Hamilton", 
        "6": "Luminox", 
        "99": "Michael Kors", 
        "968": "Mont Blanc Pens", 
        "3": "Nixon", 
        "959": "Nooka", 
        "92": "Seiko", 
        "91": "Tendence", 
        "7": "Tissot" 
    } 
};

var str = '';
for (var i in json.message) {
    str += json.message[i]+'\n';
}
alert(str);

it alerts in the below order –

Diesel
Armani
Nixon
Hamilton
Luminox
DKNY
Fossil
Casio
Adidas
Tendence
Seiko
Michael Kors
Nooka
Mont Blanc Pens

But I want it in below order

Adidas
Armani
Casio
Diesel
DKNY
Fossil
Hamilton
Luminox
Michael Kors
Mont Blanc Pens
Nixon
Nooka
Seiko
Tendence
Tissot

Can any one suggest me what approach I should adopt to get in correct order?

Any help would be greatly appreciated!

  • 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-28T06:48:49+00:00Added an answer on May 28, 2026 at 6:48 am

    Assuming you want the elements listed in alphabetical order by their value:

    var values = [];
    for(var i in json.message) {
       values.push(json.message[i]);
    }
    var str = values.sort().join('\n');
    

    Update

    To form an array of key-value pairs ordered by their (string) value:

    var values = [];
    for(var i in json.message) {
       values.push({ key: i, value: json.message[i] });
    }
    values.sort(function(a, b) { return a.value.localeCompare(b.value); });
    var str = values.map(function (kvp) { return kvp.value; }).join('\n');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my JSON array is like this; var foo = [{aid:1,atitle:Ameya R. Kadam},{aid:2,atitle:Amritpal Singh},{aid:3,atitle:Anwar Syed},{aid:4,atitle:Aratrika},{aid:5,atitle:Bharti
Hello i have this Json output and i am calling in my android app.
I want to show this json url output in table over here which is
i have this JS: $.getJSON('getMessageDetails.php', function (json) { var uc = json[4]; var uc_length
I have a DataSet consisting of XML data, I can easily output this to
I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo]
The output of this echo is not passed on to the next command using
I have this output when trying to debug Program received signal SIGSEGV, Segmentation fault
Suppose you have output like this: Word1 Word2 Word3 Word4 Where the number of
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me 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.