0

i have a 2D array that i want to sort by a certain value, here's my array:

[
  [
    {
      "Categorie": "Alimentation",
      "Label": "Trsttzp",
      "Prix": "45",
      "Date": "01/12/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Trst",
      "Prix": "65",
      "Date": "01/13/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Ts",
      "Prix": "99",
      "Date": "01/02/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Ts",
      "Prix": "99",
      "Date": "01/12/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "Haa",
      "Prix": "55",
      "Date": "01/12/2018"
    }
  ],
  [
    {
      "Categorie": "Alimentation",
      "Label": "qsd",
      "Prix": "6",
      "Date": "01/12/2018"
    }
  ]
]

i want to sort it by Date, i tried to use "fast-sort" library from npm but it doesnt seem to work, i think that the problem is that this library doesnt work with 2d arrays, and i can't find a way to do it with typescript or a libriary that supports 2d arrays :x

1 Answer 1

1

Simple enough just do it like this without a 3rd party lib

let arraysorted = array.sort((x,y) => new Date(x[0].Date) > new Date(y[0].Date));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.