function sortSize(size: string []) { return size.sort((a: string, b: string) => { const order = ["xxs", "xs", "s", "m", "l", "xl", "xxl", "2xl", "3xl", "4xl", "5xl", "one size"]; const aIndex = order.indexOf(a.toLowerCase()); const bIndex = order.indexOf(b.toLowerCase()); return aIndex - bIndex; }); } // works with this one let size: string[] = ['XL', 's', '1', '10', '2xl', '3', '0', 'xs', 'm', '3T', 'xxl', 'xxs', 'one size'];