-
-
Save hpfast/7943111 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<ul id="buh"></ul> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = [ | |
{ | |
attributes:{ | |
name:'Peter', | |
age:22, | |
dob:'2020-04-10T08:32:33Z' | |
} | |
}, | |
{ | |
attributes:{ | |
name:'Hans', | |
age:23, | |
dob:'2010-03-31T08:32:33Z' | |
} | |
} | |
]; | |
function music(a,b){ | |
var ageA = a.attributes.age.toString(); | |
var ageB = b.attributes.age.toString(); | |
var dobA = a.attributes.dob.split(/[\- : T Z]/); | |
var dobB = b.attributes.dob.split(/[\- : T Z]/); | |
console.log(dobA); | |
return dobB[0] - dobA[0]; | |
} | |
array.sort(music); | |
for(i=0;i<array.length;i++){ | |
$('#buh').append($('<li>').text(array[i].attributes.name)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment