0

Input Data

 var data =  {
    "36905b7cb": "(2019-12-26 T 13H-39M-0S) Co-Testing",
    "cad5dd7ea": "(2019-12-05 T 16H-38M-9S) Diagnosis",
    "sad4217ea": "(2020-03-05 T 16H-38M-9S) Bio-Testing"
  }

Expected Output

var data =  {
    "sad4217ea": "(2020-03-05 T 16H-38M-9S) Bio-Testing"
    "36905b7cb": "(2019-12-26 T 13H-39M-0S) Co-Testing",
    "cad5dd7ea": "(2019-12-05 T 16H-38M-9S) Diagnosis"
  }

we have to arrange the data in the sorted based on date.Not the KEYS

11
  • Does this answer your question? Sort JavaScript object by key Commented Apr 22, 2020 at 8:24
  • Are you sure that you need it to be an object not an Array? Because the keys of an Object are not ordered Commented Apr 22, 2020 at 8:25
  • @ManishSundriyal in JS you have keys order guaranteed by the spec so it's safe to use. It means that you can iterate over object keys in the order they were added Commented Apr 22, 2020 at 8:27
  • @ManishSundriyal we have an object in which to order data based on date. Commented Apr 22, 2020 at 8:27
  • 1
    @SebastianKaczmarek Sorry, for the confusion. Commented Apr 22, 2020 at 8:31

1 Answer 1

1

You can use the array util functions like reduce, sort. enter image description here

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

1 Comment

if data = { "787": "(2019-12-04 T 21H-17M-0S) Ortho 1", "456": "(2019-12-04 T 23H-58M-0S) Cardiologist Research", "123": "(2019-12-05 T 19H-0M-0S) Survey shoot 2", "36905b7cb": "(2019-12-26 T 13H-39M-0S) Co-Testing", "cad5dd7ea": "(2019-12-05 T 16H-38M-9S) Diagnosis", "sad4217ea": "(2020-03-05 T 16H-38M-9S) Bio-Testing"} Its not working on this input.Please help me

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.