Convert a javascript object to an array

The following code will convert an object to an array in Javascript, minding the order of the keys.

The keys will be replaced with numbers:

/**
 * Convert an object to an array
 * @param {object} obj The object to convert
 */
var obj2array = function (obj) {
	var out = [],
		keys = Object.keys(obj),
		i,
		len = keys.length;

	keys.sort();

	for (i = 0; i < len; i++) {
		out.push(obj[keys[i]]);
	}
	
	return out;
};Code language: PHP (php)