View Single Post
Old 02-28-2013, 02:37 AM   PM User | #1
JonBMN
New Coder

 
Join Date: Feb 2013
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
JonBMN is an unknown quantity at this point
sorting through objects in an array

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;
	}
}

Last edited by JonBMN; 02-28-2013 at 07:24 PM..
JonBMN is offline   Reply With Quote