noxon
Version:
Better JSON parsing and manipulation in TypeScript.
18 lines (17 loc) • 404 B
JavaScript
const sortObjectArray = (array, key) => {
try {
if (!array) throw new Error("Array must be defined");
array.sort((a, b) => {
const textA = a[key].toUpperCase();
const textB = b[key].toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
return array;
} catch (error) {
console.error(error);
return void 0;
}
};
export {
sortObjectArray
};