I have an array of objects, like this:
array = [ {userId: 'Y-10'}, {userId: 'Y-1'}, {userId: 'Y-14'}, {userId: 'Y-24'} ];
I need to sort the array by the userId
in order. The results should be in this order: 'Y-1','Y-10','Y-14','Y-24'
I tried using a sort like this array.sort((a,b) => ("" + a.userId).localeCompare(b.userId, undefined, {numeric: true}));
But this doesnt work. How can I sort my array to yield the results i'm seeking?