<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: JavaScript: Sort object by a value</title>
	<atom:link href="http://wolfram.kriesing.de/blog/index.php/2008/javascript-sort-object-by-a-value/feed" rel="self" type="application/rss+xml" />
	<link>http://wolfram.kriesing.de/blog/index.php/2008/javascript-sort-object-by-a-value</link>
	<description>all the other blogs have such cool names, I don't know one ...</description>
	<pubDate>Thu, 09 Feb 2012 17:03:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Naveen</title>
		<link>http://wolfram.kriesing.de/blog/index.php/2008/javascript-sort-object-by-a-value/comment-page-1#comment-424015</link>
		<dc:creator>Naveen</dc:creator>
		<pubDate>Mon, 04 Apr 2011 06:13:09 +0000</pubDate>
		<guid isPermaLink="false">http://wolfram.kriesing.de/blog/?p=228#comment-424015</guid>
		<description>I am also searching for similar kind of sorting. Kindly give me an idea how do we implement this in a class using a private method.</description>
		<content:encoded><![CDATA[<p>I am also searching for similar kind of sorting. Kindly give me an idea how do we implement this in a class using a private method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Felipe Delgado</title>
		<link>http://wolfram.kriesing.de/blog/index.php/2008/javascript-sort-object-by-a-value/comment-page-1#comment-413052</link>
		<dc:creator>Felipe Delgado</dc:creator>
		<pubDate>Tue, 12 Oct 2010 17:29:28 +0000</pubDate>
		<guid isPermaLink="false">http://wolfram.kriesing.de/blog/?p=228#comment-413052</guid>
		<description>I tried to make work the array like you have, and I can't; instead of, I made an array of JSON objects, like this:

var maxSpeed = [
{vehicle:'car', velocity:300}, 
{vehicle:'bike',velocity:60}, 
{vehicle:'motorbike',velocity:200}, 
{vehicle:'airplane', velocity:1000},
{vehicle:'helicopter',velocity:400}, 
{vehicle:'rocket', velocity:8*60*60}
];

then, I used a sorting function that sort the array using the velocity property of the objects.

function SortByVelocity(a,b)
{ return a.velocity - b.velocity; }

maxSpeed.sort(SortByVelocity);

and it's works very fine!</description>
		<content:encoded><![CDATA[<p>I tried to make work the array like you have, and I can&#8217;t; instead of, I made an array of JSON objects, like this:</p>
<p>var maxSpeed = [<br />
{vehicle:'car', velocity:300},<br />
{vehicle:'bike',velocity:60},<br />
{vehicle:'motorbike',velocity:200},<br />
{vehicle:'airplane', velocity:1000},<br />
{vehicle:'helicopter',velocity:400},<br />
{vehicle:'rocket', velocity:8*60*60}<br />
];</p>
<p>then, I used a sorting function that sort the array using the velocity property of the objects.</p>
<p>function SortByVelocity(a,b)<br />
{ return a.velocity - b.velocity; }</p>
<p>maxSpeed.sort(SortByVelocity);</p>
<p>and it&#8217;s works very fine!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Frank</title>
		<link>http://wolfram.kriesing.de/blog/index.php/2008/javascript-sort-object-by-a-value/comment-page-1#comment-202707</link>
		<dc:creator>Thomas Frank</dc:creator>
		<pubDate>Mon, 26 May 2008 22:58:15 +0000</pubDate>
		<guid isPermaLink="false">http://wolfram.kriesing.de/blog/?p=228#comment-202707</guid>
		<description>I wrote a sorter for arrays of objects a while ago that also comes to mind:
http://www.thomasfrank.se/sorting_things.html</description>
		<content:encoded><![CDATA[<p>I wrote a sorter for arrays of objects a while ago that also comes to mind:<br />
<a href="http://www.thomasfrank.se/sorting_things.html" rel="nofollow">http://www.thomasfrank.se/sorting_things.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter higgins</title>
		<link>http://wolfram.kriesing.de/blog/index.php/2008/javascript-sort-object-by-a-value/comment-page-1#comment-197322</link>
		<dc:creator>peter higgins</dc:creator>
		<pubDate>Tue, 20 May 2008 17:38:12 +0000</pubDate>
		<guid isPermaLink="false">http://wolfram.kriesing.de/blog/?p=228#comment-197322</guid>
		<description>function sortObj(theObj, idx){
	var sortable = [];
	for(var i in theObj){
		sortable.push([i, theObj[i]]);
	}
	sortable.sort(function(a,b){
		return a[idx] - b[idx];
	});
	return dojo.map(sortable,function(elm){ return elm[0]; });
}

var obj = {
	car: 300, bike:60, motorbike:200, airplane:1000, 
	helicopter: 500, rocket: 8*60*60
};


console.log(sortObj(obj,1));</description>
		<content:encoded><![CDATA[<p>function sortObj(theObj, idx){<br />
	var sortable = [];<br />
	for(var i in theObj){<br />
		sortable.push([i, theObj[i]]);<br />
	}<br />
	sortable.sort(function(a,b){<br />
		return a[idx] - b[idx];<br />
	});<br />
	return dojo.map(sortable,function(elm){ return elm[0]; });<br />
}</p>
<p>var obj = {<br />
	car: 300, bike:60, motorbike:200, airplane:1000,<br />
	helicopter: 500, rocket: 8*60*60<br />
};</p>
<p>console.log(sortObj(obj,1));</p>
]]></content:encoded>
	</item>
</channel>
</rss>

