function Player() { var score; this.getScore = function() { return score; } this.setScore = function(sc) { score = sc; } } function compare(playerA, playerB)
you can also use like below:
var a = []; a.push(obj1); a.push(obj2); a.sort(compare);
so you can use push method rather than an integer index