The comparison function must return an integer. sort checks whether it's negative, zero, or positive, and uses that to determine how the two elements should be ordered. So do:
elems.sort(function(a, b) {
return a.id - b.id;
});
Or, in modern ES6 style:
elems.sort((a, b) => a.id - b.id);