I'm trying to sort an array of objects with this function. objArray = [{q:2}, {q:1}, {q:3}] with a key of "q". so that it will return [{q:1}, {q:2}, {q:3}].
heres what I've got so far, I'm not sure if my logic is the one thing thats messed up or if I'm not using the correct parameter for the .sort method. please help! please no regexp or no answers just a push in the right direction please and thank you.
Code:
function sortingTime(objArray, key) {
for (var i = 0; i < objArray.length; i++) {
objArray = parseFloat(objArray[i]);
objArray.sort(key);
return objArray;
}
}