by
16
7
4,772
3
Top 1% !
Popular
Famous
Nice
Easy-to-find
Specified
Pattern
Popularity: 1712nd place
Languagegroovy
Languagejavascript
LicenseMIT_X11

kwik dirty arraySort....

kwik example of a complex array sort
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/249667/kwik-dirty-arraySort----?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// sort a complex array var mehAry = [{id: 140, name: "abc", age: "twenty"}, {id: 62009, name: "def", age: "thirty"}, {id: 3030, name: "ghi", age: "forty" }, {id: 455, name: "jkl", age: "fifty" }]; function complexSort (itm1, itm2) { var a = itm1.id, b = itm2.id; return (a - b); } var sortedArray = mehAry.sort(complexSort); // sortedArray = [{id: 140, name: "abc", age: "twenty"},{id: 455, name: "jkl", age: "fifty" }, // {id: 62009, name: "def", age: "thirty"},{id: 3030, name: "ghi", age: "forty" }];
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus