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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:42:46+00:00 2026-06-01T19:42:46+00:00

Im trying to sort the items from an object/array by their name item, I

  • 0

Im trying to sort the items from an object/array by their “name” item,

I used this page for reference Sort array of objects and build the piece of code below:

var alphabet = {
    a: 1,
    b: 2,
    c: 3,
    d: 4,
    e: 5,
    f: 6,
    g: 7,
    h: 8,
    i: 9,
    j: 10,
    k: 11,
    l: 12,
    m: 13,
    n: 14,
    o: 15,
    p: 16,
    q: 17,
    r: 18,
    s: 19,
    t: 20,
    u: 21,
    v: 22,
    w: 23,
    x: 24,
    y: 25,
    z: 26
}

var test = {
    item: {
        name: "Name here",
        email: "example@example.com"
    },

    item2: {
        name: "Another name",
        email: "test@test.com"
    },

    item3: {
        name: "B name",
        email: "test@example.com"
    },

    item4: {
        name: "Z name",
        email: "example@text.com"
    }
};
test.sort(function (a, b) {return alphabet[a.name.charAt(0)] - alphabet[b.name.charAt(0)]});

console.log(test);

Unfortunately no errors are returned and the console.log doesn’t returns anything either.
Any help is greatly appreciated!

EDIT:
After the answer has been given, it seemed the variable “test” was required to be an array, however, the variable was generated dynamically in an external library, therefor I made this little piece of code.
If anyone has the same issue, feel free to use it.

var temp = [];
$.each(test, function(index, value){
    temp.push(this);
});

//temp is the resulting array
  • 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-01T19:42:47+00:00Added an answer on June 1, 2026 at 7:42 pm

    test is an object, not an array. Perhaps you want this:

    var test = [
        {
            name: "Name here",
            email: "example@example.com"
        },
        ⋮
    ];
    

    If you need the item, item1, … to be retained against each object, you could add them as fields of each object:

    var test = [
        {
            id: "item",
            name: "Name here",
            email: "example@example.com"
        },
        ⋮
    ];
    

    To sort alphabetically, you need a case-insensitive comparator (and forget the alphabet object):

    compareAlpha = function(a, b) {
      a = a.name.toUpperCase(); b = b.name.toUpperCase();
      return a < b ? -1 : a > b ? 1 : 0;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem. I'm trying to sort the items from 1 array (name:
Trying to sort this array of objects according to (1) depth and (2) weight,
I'm trying to order items based on an attribute value: <xsl:apply-templates select=Question> <xsl:sort order=ascending
I'm trying to implement drag/drop/sort between 2 list elements: <ul id=first> <li>item 1</li> <li>item
So I'm trying to sort an array of pointers as seen below. The problem
I'm trying to sort a multidimensional array in objective-c i know that i can
How can I get a specific value from an object? I'm trying to get
I'm trying to figure out what this sort of thing is called, and eventually
I'm trying to use jQueryUI draggable/droppable/sortable to move (not copy) items from a source
I'm trying to sort a vector of objects using a predicate function and I'm

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.