Probé un mapa y un bucle forEach y todavía no puedo ordenarlo por orden alfabético. No estoy seguro de lo que me estoy perdiendo aquí.
Mi matriz:
const filtData = [ [ { gameType: "Rowing", }, { gameType: "Rowing", }, { gameType: "Rowing", }, ], [ { gameType: "Golf", }, { gameType: "Golf", }, { gameType: "Golf", }, ], [ { gameType: "Soccer", }, { gameType: "Soccer", }, { gameType: "Soccer", }, ], [ { gameType: "Baseball", }, { gameType: "Baseball", }, { gameType: "Baseball", }, ], ]js:
filtData.forEach(d => d.sort((a,b) => a.gameType - b.gameType)) console.log(filtData) /* <--fails */ const sortedData = filtData.map((d) => d.sort((a, b) => { return a.gameType - b.gameType; })); console.log("sortedData", sortedData)/* <--fails */JsFiddle: https://jsfiddle.net/eL510oq3/
Algunos puntos:
String#localeCompareforEach o .map , solo sort const filtData = [ [ { gameType: "Rowing", }, { gameType: "Rowing", }, { gameType: "Rowing", }, ], [ { gameType: "Golf", }, { gameType: "Golf", }, { gameType: "Golf", }, ], [ { gameType: "Soccer", }, { gameType: "Soccer", }, { gameType: "Soccer", }, ], [ { gameType: "Baseball", }, { gameType: "Baseball", }, { gameType: "Baseball", }, ], ]; filtData.sort((a,b) => a[0].gameType.localeCompare(b[0].gameType)) console.log(filtData);Clasificación de objetos de matriz en el método de orden ASC 1:
let arrayConcat = filtData.reduce((preValue, curValue) => { return preValue.concat(curValue) }, []); let result = arrayConcat.sort((a, b) => { return a.gameType.localeCompare(b.gameType); }) console.log(result);