Sorting in Javascript is quite easy.
For example, I have an array call "my_object_array" where "my_object" is an object that contains "customer_code" and "customer_name" properties. To sort the data by customer_code, just run the following code:
var f = 'customer_code';
my_object_array.sort(function (a, b) {
return a[f] - b[f];
});
To sort the data in descending order, you just need to swap the "a" and "b".
my_object_array.sort(function (a, b) {
return b[f] - a[f];
});
Cool huh?
Subscribe to:
Post Comments (Atom)
We are moving
We are moving this blog to our new blog site: https://ciysys.com/blog/nodejs.htm
-
Overview Usually, we start developing a new system with designing database and then writing codes. If you are not a fan of ORM, you will h...
-
Below is the sample HTML which will hide the URL at the page header when printing with Javascript. <html moznomarginboxes > ...
-
You can draw a simple pie chart & doughnut chart with SVG + CSS. This is quite simple and straight forward. But the limitation is that i...
No comments:
Post a Comment