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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:18:12+00:00 2026-05-25T00:18:12+00:00

Alright Odd results, not so much as they are expected. However I’m not sure

  • 0

Alright Odd results, not so much as they are expected. However I’m not sure how to over come it, I am having one of those days where every logical thing is the equivalent of a massive brain fart for me. Anyway. Lets say for the sake of ease. My array is numeric only nothing else in there.. My array ranges from 1-50 so my results upon sorting it are similar to 1, 10, 11, 12, 13…. 2, 20, 21, 22, 23… etc. When I need it to go like 1,2,3,4,5,6,7,8,9,10,11,12…

My simple little canned function is..

function sortJSONresultsByWidgetID(a,b)
{   
    if(parseInt(a.wigetID) == parseInt(b.wigetID))
    {
        return 0;
    }
    return parseInt(a.wigetID) > parseInt(b.wigetID) ? 1 : -1;
}

for reference I parseInt due to the JSON the way my JSON handles when I post it back and forth from the DB, I store the actual JSON in the DB and when passing it to the PHP it wraps quotes around the number turning them from INT to string (or from what I notice that may be browser based).

So here I am stuck now cause I want these things listed in a particular order and my brain wont work today.

EDIT example of me sorting results:

dashboardJSON.widgets.sort(sortJSONresultsByWidgetID);
  • 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-25T00:18:12+00:00Added an answer on May 25, 2026 at 12:18 am

    You need to parse the ints with a radix of 10 and use the === operator instead of ==. I think that should do it.

    function sortJSONresultsByWidgetID(a,b)
    {
        var widgetAId = parseInt(a.wigetID, 10);
        var widgetBId = parseInt(b.wigetID, 10);
    
        if(widgetAId === widgetBId)
        {
            return 0;
        }
        return widgetAId > widgetBId ? 1 : -1;
    }
    

    UPDATE – Here’s with Ellian’s optimization:

    function sortJSONresultsByWidgetID(a,b)
    {
        return parseInt(a.wigetID, 10) - parseInt(b.wigetID, 10);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright so this is an odd one... I have an application built in ColdFusion
Alright, here's an odd one from an MS Access database I'm running. I have
Alright not sure what to do and i am honestly bit lost. What I
Alright, I have a rather odd question here. I feel much more comfortable writing
Alright guys, I have looked on the internet for ages and simply could not
Alright, I'm not the best with JOIN's and after all these years of working
Alright, I'm using form.target to open content in a new window. However, when I
Alright, so I think I'm pretty close to having what I need, but I'm
Alright, I found out in this question that polling sockets does not scale, so
Alright, I am so close to finishing this I can taste it. Over 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.