[Vuejs]-VueJs – Problem with alphabetic sorting in ArrayList

0đź‘Ť

EDIT:
alright, with a cleaner object

const items = [
  {
    artist: "Petit Biscuit",
    type: "rap",
    img:
      "https://media.virginradio.fr/article-4260166-head-f8/petit-biscuit.jpg",
    stage: "Scène A",
    day: "Samedi",
    hour: "22h",
  },
  {
    artist: "Booba",
    type: "rock",
    img:
      "https://www.parisladefense-arena.com/uploads/2018/10/3764-booba-orig-2.jpg",
    stage: "Scène B",
    day: "Vendredi",
    hour: "23h",
  },
  {
    artist: "Vald",
    type: "metal",
    img:
      "https://cdn.radiofrance.fr/s3/cruiser-production/2019/04/05e9523a-428f-4798-ad07-c4abcc70acfa/801x410_vald_album_2019.jpg",
    stage: "Scène C",
    day: "Samedi",
    hour: "23h",
  },
  {
    artist: "Jean Schultheis",
    type: "rap",
    img:
      "https://static1.purepeople.com/articles/6/30/54/86/@/4322687-semi-exclusif-jean-schultheis-vendre-950x0-1.jpg",
    stage: "Scène A",
    day: "Samedi",
    hour: "00h",
  },
]

items.sort((a, b) => a.artist.localeCompare(b.artist))

This one get’s them ordered properly: Booba, Jean Schultheis, Petit biscuit and lastly Vald.


This one should work.

let items = ['réservé', 'Premier', 'Cliché', 'communiqué', 'café', 'Adieu'];
items.sort( (a, b) => a.localeCompare(b, 'fr', {ignorePunctuation: true}));
// ['Adieu', 'café', 'Cliché', 'communiqué', 'Premier', 'réservé'] 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#sort_an_array

Leave a comment