Linked Questions

4226 votes
61 answers
3.5m views

Sort array of objects by string property value

I have an array of JavaScript objects: var objs = [ { first_nom: 'Laszlo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: '...
Tyrone Slothrop's user avatar
1 vote
1 answer
229 views

Sorting a array of objects based on the value of one of the properties of the objects in javascript [duplicate]

Possible Duplicate: Sort JavaScript array of Objects based on one of the object’s properties I have an object which has a property called z: function building(z) { this.z = z; } Let's say I ...
Jamie Fearon's user avatar
  • 2,634
0 votes
0 answers
22 views

Sorting an array based on objectified language representation ((k,v)-array) [duplicate]

I need to sort an array of html options, based on their innerHTML, but these vary depending on country. I'm using javascript/jquery for this. Currently I have 6 different languages that need support; ...
AbaccusX's user avatar
1264 votes
23 answers
1.5m views

Sort array by firstname (alphabetically) in JavaScript [duplicate]

I got an array (see below for one object in the array) that I need to sort by firstname using JavaScript. How can I do it? var user = { bio: null, email: "[email protected]", ...
Jonathan Clark's user avatar
133 votes
1 answer
230k views

Sorting arrays numerically by object property value

How would you sort this array with these objects by distance, so that you have the objects sorted from smallest distance to biggest distance? [ { distance: 3388, duration: "6 mins", from: &...
Harry's user avatar
  • 13.4k
20 votes
5 answers
87k views

Sort array on key value

I have a function which sorts by name currently and an array of value / key pairs. I wonder how can I pass the key on which sort is being performed so I can call the same function every time like so: ...
Toniq's user avatar
  • 5,138
2 votes
1 answer
2k views

How do I perform a merge sort based on the property of an object (rather than an Array)?

Background Using JavaScript, I need to sort a large JSON object based on a given property of that object. I am assuming that a merge sort is the fastest approach. If this is not the fastest ...
Matt Cashatt's user avatar
  • 24.3k
0 votes
3 answers
878 views

Need to sort the Javascript array according to some logic [duplicate]

Possible Duplicate: How to sort an array of javascript objects? I have a array myResponse.students[i] I calculate the Total marks for every student in the array through some logic and now i want ...
coderslay's user avatar
  • 14.4k
1 vote
3 answers
927 views

Sort array of arrays

I have the following data: var data = [[{x:"c", y:10}, {x:"a", y:20}, {x:"b", y:4}], [{x:"c", y:14}, {x:"a", y:22}, {x:"b", y:9}], [{x:"c", y:24}, {x:"a", y:65}, {x:"b", y:46}]] I need to order the (...
user393750's user avatar
1 vote
1 answer
582 views

How to sort my objects list by date which is returned from server by a ajax call

I send an Ajax call to server, then server returns me the xml data which contain a list of objects. Each object in the list contain a "date" attribute. In the success function of the Ajax call, I ...
Leem's user avatar
  • 18.5k
-2 votes
3 answers
163 views

How to sort object values in JavaScript when keys are numbers?

let's say I have such weird code: var weirdo = {}; var ids = [10, 30, 11, 1, 4, 2]; var producers = ['Ford','Rover','BMW','Fiat','Renault','Mitsubishi']; var n = producers.length; for(var i=0; i<n;...
marverix's user avatar
  • 7,755
-1 votes
1 answer
350 views

How to search JSON using JavaScript

{"LastName":"Micheal","FirstName":"John"} I have a Json data. When i type my last name or a single character in my text field, it should search this value... and get me the response. My json data is ...
theJava's user avatar
  • 15.1k